Ubuntu Network Interface Config: Step‑by‑Step Guide
In this article
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
- Open a terminal. Press
Ctrl+Alt+Tor connect via SSH if you are working remotely. - Check your current network configuration. Run
ip ato list interfaces andcat /etc/netplan/*.yamlorcat /etc/network/interfacesto see existing settings. - 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/interfacesis the standard method. - 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, runsudo cp /etc/network/interfaces /etc/network/interfaces.bak. - 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.4Adjusteth0to match your interface name (useip ato confirm). If you need VLANs, add avlans:section undernetwork:. - Apply Netplan changes. Execute
sudo netplan apply. If you see errors, review the YAML for indentation or syntax mistakes. - Verify connectivity. Ping a public host:
ping -c 4 8.8.8.8. If successful, rundig @8.8.8.8 www.google.comto confirm DNS resolution. - 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.4Replaceeth0and the IP details with your own. For DHCP, useiface eth0 inet dhcp. - Restart networking. Run
sudo systemctl restart networkingorsudo service networking restartdepending on your init system. - Confirm the changes. Use
ip aandcat /etc/resolv.confto ensure the IP and DNS values match what you set. - Save a snapshot of the running configuration. For Netplan,
sudo netplan --debug applywill log detailed output. For interfaces, check/var/log/syslogfor boot-time messages.
Common Mistakes
- Using tabs instead of spaces in YAML files. Netplan requires 2‑space indentation.
- Leaving the renderer set to
NetworkManagerwhen you wantnetworkdfor server setups. - Incorrect interface names (e.g.,
eth0vsenp3s0). Always verify withip 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/interfacesis ignored unlessifupdownis installed.
Tips
- Use
netplan trybeforeapplyto 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
vlanidline under the VLAN definition and ensure the parent interface is set tobond0if you are bonding. - For servers that need high availability, consider using
bond0withmode=active-backupin Netplan. - Always test connectivity after each change; a single typo can bring the network down.
Troubleshooting
- Network is down after applying changes. Reboot the machine or run
sudo netplan applyagain. Checkjournalctl -u systemd-networkdfor error messages. - No IP address assigned. Verify that
dhcp4: no(oriface eth0 inet static) is present and that the address block is correctly indented. Ensure the subnet mask matches the gateway's network. - DNS resolution fails. Confirm
nameserversentries are correct and that/etc/resolv.confis not overwritten by another service likesystemd-resolved. If usingsystemd-resolved, adddns-searchandfallback-serversas needed. - Ping works but HTTP fails. Check firewall rules:
sudo ufw status. Ensure ports 80/443 are allowed or temporarily disable the firewall to test. - Interface name changes after reboot. Some Ubuntu releases rename interfaces to predictable names (e.g.,
enp3s0). Useudevrules ornetplandevice names that match the new naming scheme. - Netplan syntax error. Run
sudo netplan tryto 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.