Smart Systems for Home

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

Linux Configure Network Step by Step Guide

· 5 min read · Home Networking

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Wireless Configuration Example
  7. Using NetworkManager from the Command Line
  8. Common Configuration Files and Locations
  9. Frequently Asked Questions

Configuring a Linux network allows you to connect to the internet, set up static IPs, or manage local networks. This guide shows how to configure network settings using command-line tools and configuration files, suitable for most Linux distributions like Ubuntu, Debian, or CentOS.

What You'll Need

  • A running Linux system with sudo access
  • Network interface to configure (wired or wireless)
  • Terminal access (e.g., GNOME Terminal, Konsole, or SSH)
  • Internet connection (if setting up dynamic IP)
  • Optional: Static IP details (IP address, subnet mask, gateway, DNS servers)

Step-by-Step

  1. Open your terminal application. Use Ctrl + Alt + T on most desktop environments or search for 'Terminal' in your app menu.
  2. Check network interfaces with the command:
    ip link show
    Look for the name of your network interface (e.g., eth0 for Ethernet or wlan0 for wireless). This command will also show if the interface is up or down. If an interface is down, bring it up with:
    sudo ip link set eth0 up
    Replace eth0 with your interface name.
  3. For dynamic IP (DHCP), use dhclient to request an IP from a DHCP server:
    sudo dhclient eth0
    Replace eth0 with your interface name. This command requests an IP address from the network's DHCP server. If the command fails, it could be due to an incorrect interface name, a firewall block, or a lack of DHCP server on the network.
  4. To set a static IP, open the configuration file with a text editor. For netplan (used in Ubuntu 18.04+, Debian 11+), edit:
    sudo nano /etc/netplan/01-netcfg.yaml
    Add or modify the YAML 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
              - 8.8.4.4
    Replace the IP addresses and interface name as needed. YAML syntax is strict: incorrect indentation or formatting can prevent the file from working. Always validate with:
    netplan apply
    This command checks the syntax before applying changes, preventing boot issues.
  5. Apply your changes with:
    sudo netplan apply
  6. For older systems using interfaces (Debian/Ubuntu older versions), edit:
    sudo nano /etc/network/interfaces
    Add a static IP configuration like:
    auto eth0
    iface eth0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    gateway 192.168.1.1
    nameserver 8.8.8.8
    Then restart the interface:
    sudo systemctl restart networking
  7. Verify your configuration with:
    ip addr show
    and
    ping -c 4 google.com
    to ensure connectivity. If ping fails, check if the gateway is reachable with:
    ping 192.168.1.1
    and test DNS resolution with:
    nslookup google.com

Common Mistakes

  • Typing the interface name incorrectly (e.g., eth0 vs. enp0s3). Use ip link to verify the exact name.
  • Using the wrong configuration file for the system (e.g., using netplan when the system uses interfaces). Check your distribution's documentation or use find /etc/ -name "interfaces" or find /etc/ -name "*.yaml" to locate the right file.
  • Forgetting to run sudo netplan apply after making changes. Netplan does not apply changes automatically unless you use the netplan apply command.
  • Incorrectly formatting YAML files (netplan), such as missing spaces, tabs, or invalid syntax. Use a YAML validator or run netplan apply to catch errors before rebooting.
  • Not restarting the network service after updating configuration files. Run sudo systemctl restart networking or sudo systemctl restart NetworkManager to activate changes.

Tips

  • Use ip route to check routing table and verify gateway settings. Look for the default route with ip route show.
  • Use nmcli for NetworkManager-based setups (e.g., GNOME desktops) with:
    nmcli connection modify eth0 ipv4.method manual ipv4.addresses 192.168.1.100/24 ipv4.gateway 192.168.1.1 ipv4.dns 8.8.8.8
    This avoids editing configuration files directly and is useful for quick configuration changes.
  • Back up configuration files before editing them. Use cp /etc/netplan/01-netcfg.yaml /etc/netplan/01-netcfg.yaml.bak to create a backup.
  • Use ping and traceroute to test connectivity to internal and external IPs. For example, ping 192.168.1.1 checks local network connectivity, while ping google.com checks internet access.

Troubleshooting

When your network configuration doesn't work, follow these steps:

  1. Check for typos in your configuration file using sudo nano /etc/netplan/01-netcfg.yaml or sudo nano /etc/network/interfaces.
  2. Validate your YAML syntax in Netplan with:
    netplan apply
    If there's a syntax error, it will display the line and column. Fix the error before applying the changes.
  3. Ensure the interface is up:
    sudo ip link set eth0 up
  4. Check DHCP status with:
    dhclient -v eth0
  5. Restart the network service:
    sudo systemctl restart NetworkManager
    or
    sudo systemctl restart networking
  6. If using NetworkManager, use:
    nmcli device disconnect eth0
    nmcli device connect eth0
  7. Check logs with:
    journalctl -u networking
    or
    journalctl -u NetworkManager
  8. If all else fails, reboot the system:
    sudo reboot

Wireless Configuration Example

For wireless interfaces using Netplan, you can configure them like this:
network:
  version: 2
  wifis:
    wlan0:
      dhcp4: false
      addresses:
        - 192.168.1.100/24
      gateway4: 192.168.1.1
      nameservers:
        addresses:
          - 8.8.8.8
      access-points:
        'MyWiFi':
          password: 'mypassword'
Apply the configuration with netplan apply, and confirm the interface is up with ip link show wlan0 and ip addr show wlan0.

Using NetworkManager from the Command Line

If your system uses NetworkManager, you can manage connections via nmcli. For example:
nmcli device status
This shows the current state of network interfaces. To connect to a wireless network:
nmcli device wifi connect 'MyWiFi' password 'mypassword' ifname wlan0
This is useful for scripting or when working in headless environments without a GUI.

Common Configuration Files and Locations

  • /etc/netplan/ – Netplan YAML configuration files (Ubuntu 18.04+, Debian 11+)
  • /etc/network/interfaces – Static IP configuration for older Debian/Ubuntu systems
  • /etc/NetworkManager/ – NetworkManager configuration files

Frequently Asked Questions

How do I find my current IP address on Linux?

Use ip addr show or hostname -I in the terminal.

Can I use a GUI to configure the network?

Yes, desktop environments like GNOME or KDE offer network settings in the system settings. Look for Network or Wi-Fi settings.

Is Netplan the same on all Linux distributions?

No. Netplan is used in Ubuntu and some Debian derivatives. Older systems may use interfaces or NetworkManager.

I changed my IP and now I can't connect. How do I revert?

Boot into a live USB, edit the configuration file with nano, or use a fallback IP if one was configured.

How do I set up a wireless connection?

Use nmcli for NetworkManager or configure netplan for wireless with SSID and password.

What if my system doesn't use Netplan?

Check your /etc/network/interfaces file for Debian-based systems or use nmcli for NetworkManager-based systems.