Configure Linux Network Settings
In this article
Configuring the network in Linux ensures your system can connect to the internet or local networks. This guide covers configuring both wired and wireless interfaces with static or dynamic IP addresses using standard tools like nmcli, ip, or netplan, depending on your distribution. You'll need root access and a working internet connection to verify settings.
What You'll Need
- Linux system (Ubuntu, Fedora, Debian, etc.) with terminal access
- Root or sudo privileges
- Internet connection or network cable
- Network details (IP address, gateway, DNS, subnet mask if using static configuration)
Step-by-Step
- Open the terminal. You can do this by searching for "Terminal" in your application menu or using a keyboard shortcut (usually Ctrl+Alt+T).
- Identify the network interface. Run
ip link showornmcli deviceto list your network devices. Note the name of the interface you want to configure (e.g.,eth0for Ethernet orwlan0for Wi-Fi). - Choose a configuration method. Most modern systems use
NetworkManager(managed bynmcli) ornetplan(used in Ubuntu-based distributions). Check which is in use withwhich nmcliorwhich netplan. - For NetworkManager (nmcli):
- Run
nmcli connection showto view existing connections. - Edit a connection with
nmcli connection edit, or add a new one withnmcli connection add type ethernet ifname eth0. - Set a static IP with
ipv4.addresses 192.168.1.100/24,ipv4.gateway 192.168.1.1, andipv4.dns 8.8.8.8. - Save and activate the connection with
nmcli connection up.
- Run
- For netplan (Ubuntu-based):
- Open the netplan configuration file with
sudo nano /etc/netplan/01-netcfg.yaml. - Set the interface configuration, for example:
network: version: 2 ethernets: eth0: addresses: - 192.168.1.100/24 gateway4: 192.168.1.1 nameservers: addresses: - 8.8.8.8 - Save the file and apply changes with
sudo netplan apply.
- Open the netplan configuration file with
- Verify the configuration. Use
ip addr showornmcli device showto confirm the IP address and settings are applied. - Test connectivity. Ping a known host with
ping google.comto verify internet access.
Common Mistakes
- Using incorrect syntax in the YAML file for Netplan (e.g., using tabs instead of spaces or incorrect indentation).
- Not matching the interface name with the one listed in
ip link showornmcli device. - Forgetting to enable the connection after editing with
nmcli connection up. - Configuring the wrong type of network (e.g., setting up Wi-Fi with an Ethernet configuration).
Tips
- Use
nmclifor interactive configuration if you're unsure about syntax. - Always back up your netplan or NetworkManager configuration files before making changes.
- Verify DNS settings with
nslookup google.comordig google.comif DNS is not resolving correctly. - Use a graphical tool like GNOME Network Manager or KDE Network Manager if you're less comfortable with the command line.
Troubleshooting
If the network does not work after configuration, follow these steps:
- Check for typos. Use
nmcli connection showorcat /etc/netplan/01-netcfg.yamlto verify syntax. - Restart the network service. Try
sudo systemctl restart NetworkManagerorsudo netplan apply. - Verify the interface is up. Use
ip link showand ensure the interface is not down. - Check the physical connection. Ensure the Ethernet cable is plugged in or the Wi-Fi is enabled.
- Test with a dynamic IP. Temporarily set
ipv4.method autoinnmcliordhcp4: yesin netplan and restart to see if DHCP works. - Check system logs. Use
journalctl -u NetworkManagerorjournalctl -u systemd-networkdto look for errors.
Frequently Asked Questions
Can I use both NetworkManager and netplan on the same system?
No, they are incompatible. Choose one method and stick with it, or disable one before using the other.
How do I restore default settings if I messed up the configuration?
Revert to a known working configuration file or use a live USB to restore from a backup.
Why is my network not working after I applied a static IP?
Ensure the IP, gateway, and DNS settings are correct and that the interface is enabled and connected.
How can I switch from static to dynamic IP?
With NetworkManager, use nmcli connection modify . For netplan, set dhcp4: yes and run sudo netplan apply.
What if I have multiple network interfaces?
Configure each one individually using their respective interface names in the configuration files or nmcli commands.
How do I save my configuration so it survives a reboot?
For NetworkManager, use nmcli connection save. For netplan, ensure the /etc/netplan/ file is saved and run sudo netplan apply.