Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Configure Linux Network Settings

· 4 min read · Home Networking

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

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

  1. Open the terminal. You can do this by searching for "Terminal" in your application menu or using a keyboard shortcut (usually Ctrl+Alt+T).
  2. Identify the network interface. Run ip link show or nmcli device to list your network devices. Note the name of the interface you want to configure (e.g., eth0 for Ethernet or wlan0 for Wi-Fi).
  3. Choose a configuration method. Most modern systems use NetworkManager (managed by nmcli) or netplan (used in Ubuntu-based distributions). Check which is in use with which nmcli or which netplan.
  4. For NetworkManager (nmcli):
    1. Run nmcli connection show to view existing connections.
    2. Edit a connection with nmcli connection edit , or add a new one with nmcli connection add type ethernet ifname eth0.
    3. Set a static IP with ipv4.addresses 192.168.1.100/24, ipv4.gateway 192.168.1.1, and ipv4.dns 8.8.8.8.
    4. Save and activate the connection with nmcli connection up .
  5. For netplan (Ubuntu-based):
    1. Open the netplan configuration file with sudo nano /etc/netplan/01-netcfg.yaml.
    2. 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
              
    3. Save the file and apply changes with sudo netplan apply.
  6. Verify the configuration. Use ip addr show or nmcli device show to confirm the IP address and settings are applied.
  7. Test connectivity. Ping a known host with ping google.com to 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 show or nmcli 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 nmcli for 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.com or dig google.com if 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:

  1. Check for typos. Use nmcli connection show or cat /etc/netplan/01-netcfg.yaml to verify syntax.
  2. Restart the network service. Try sudo systemctl restart NetworkManager or sudo netplan apply.
  3. Verify the interface is up. Use ip link show and ensure the interface is not down.
  4. Check the physical connection. Ensure the Ethernet cable is plugged in or the Wi-Fi is enabled.
  5. Test with a dynamic IP. Temporarily set ipv4.method auto in nmcli or dhcp4: yes in netplan and restart to see if DHCP works.
  6. Check system logs. Use journalctl -u NetworkManager or journalctl -u systemd-networkd to 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 ipv4.method auto. 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.