Smart Systems for Home

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

Ubuntu Network Interface Config: Step‑by‑Step Guide

· 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

Yes, you can configure network interfaces on Ubuntu using Netplan or the legacy /etc/network/interfaces file, depending on the Ubuntu release. This guide walks you through both methods, shows how to verify your settings, and covers common pitfalls and troubleshooting steps.

What You'll Need

  • Ubuntu 20.04 LTS or newer (Netplan) or 18.04 LTS or older (interfaces)
  • Root or sudo privileges
  • Access to the terminal (Ctrl+Alt+T or SSH)
  • Knowledge of your network details: IP address, netmask, gateway, DNS servers, and optionally VLAN or bond information

Step‑by‑Step

  1. Open a terminal. Press Ctrl+Alt+T or connect via SSH if you are working remotely.
  2. Check your current network configuration. Run ip a to list interfaces and cat /etc/netplan/*.yaml or cat /etc/network/interfaces to see existing settings.
  3. Decide which configuration system to use. Ubuntu 20.04 and later use Netplan by default. If you are on 18.04 or earlier, /etc/network/interfaces is the standard method.
  4. Back up existing configuration files. For Netplan, copy the YAML file: sudo cp /etc/netplan/01-netcfg.yaml /etc/netplan/01-netcfg.yaml.bak. For interfaces, run sudo cp /etc/network/interfaces /etc/network/interfaces.bak.
  5. Edit the Netplan file (Ubuntu 20.04+). Open with a text editor: sudo nano /etc/netplan/01-netcfg.yaml. Replace the content with a minimal static configuration, for example:
    network:
      version: 2
      renderer: networkd
      ethernets:
        eth0:
          dhcp4: no
          addresses:
            - 192.168.1.100/24
          gateway4: 192.168.1.1
          nameservers:
            addresses:
              - 8.8.8.8
              - 8.8.4.4
    
    Adjust eth0 to match your interface name (use ip a to confirm). If you need VLANs, add a vlans: section under network:.
  6. Apply Netplan changes. Execute sudo netplan apply. If you see errors, review the YAML for indentation or syntax mistakes.
  7. Verify connectivity. Ping a public host: ping -c 4 8.8.8.8. If successful, run dig @8.8.8.8 www.google.com to confirm DNS resolution.
  8. Edit the interfaces file (Ubuntu 18.04 or earlier). Open with a text editor: sudo nano /etc/network/interfaces. A minimal static configuration looks like this:
    auto eth0
    iface eth0 inet static
        address 192.168.1.100
        netmask 255.255.255.0
        gateway 192.168.1.1
        dns-nameservers 8.8.8.8 8.8.4.4
    
    Replace eth0 and the IP details with your own. For DHCP, use iface eth0 inet dhcp.
  9. Restart networking. Run sudo systemctl restart networking or sudo service networking restart depending on your init system.
  10. Confirm the changes. Use ip a and cat /etc/resolv.conf to ensure the IP and DNS values match what you set.
  11. Save a snapshot of the running configuration. For Netplan, sudo netplan --debug apply will log detailed output. For interfaces, check /var/log/syslog for boot-time messages.

Common Mistakes

  • Using tabs instead of spaces in YAML files. Netplan requires 2‑space indentation.
  • Leaving the renderer set to NetworkManager when you want networkd for server setups.
  • Incorrect interface names (e.g., eth0 vs enp3s0). Always verify with ip a.
  • Forgetting to disable DHCP when setting a static address.
  • Misconfiguring DNS servers, causing name resolution failures.
  • Editing the wrong file: on newer releases, /etc/network/interfaces is ignored unless ifupdown is installed.

Tips

  • Use netplan try before apply to test a configuration for 120 seconds; if it fails, the system reverts automatically.
  • Keep a separate YAML file for each interface or network environment, naming them clearly (e.g., eth0-static.yaml).
  • When configuring VLANs, add a vlanid line under the VLAN definition and ensure the parent interface is set to bond0 if you are bonding.
  • For servers that need high availability, consider using bond0 with mode=active-backup in Netplan.
  • Always test connectivity after each change; a single typo can bring the network down.

Troubleshooting

  1. Network is down after applying changes. Reboot the machine or run sudo netplan apply again. Check journalctl -u systemd-networkd for error messages.
  2. No IP address assigned. Verify that dhcp4: no (or iface eth0 inet static) is present and that the address block is correctly indented. Ensure the subnet mask matches the gateway's network.
  3. DNS resolution fails. Confirm nameservers entries are correct and that /etc/resolv.conf is not overwritten by another service like systemd-resolved. If using systemd-resolved, add dns-search and fallback-servers as needed.
  4. Ping works but HTTP fails. Check firewall rules: sudo ufw status. Ensure ports 80/443 are allowed or temporarily disable the firewall to test.
  5. Interface name changes after reboot. Some Ubuntu releases rename interfaces to predictable names (e.g., enp3s0). Use udev rules or netplan device names that match the new naming scheme.
  6. Netplan syntax error. Run sudo netplan try to see the exact line causing the error. YAML is sensitive to tabs and spacing.

Frequently Asked Questions

Can I use Netplan on Ubuntu 18.04?

No, 18.04 uses /etc/network/interfaces by default. Netplan was introduced in 20.04.

How do I set a static IP for a Wi‑Fi interface?

Replace eth0 with your Wi‑Fi device name (e.g., wlan0) in the Netplan or interfaces file, then apply the configuration.

What is the difference between networkd and NetworkManager renderers?

Networkd is lightweight and ideal for servers; NetworkManager provides a GUI and is preferred for desktops. Choose based on your use case.

How can I revert to the previous network settings?

Restore the backup file you created earlier (e.g., sudo cp /etc/netplan/01-netcfg.yaml.bak /etc/netplan/01-netcfg.yaml) and run sudo netplan apply again.

Will editing /etc/resolv.conf directly affect Netplan?

No, Netplan writes to /etc/resolv.conf on each apply. Manual edits will be overwritten unless you disable the resolver or use systemd-resolved configuration.