Smart Systems for Home

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

Ubuntu Network Config File: How to Edit and Troubleshoot

· 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

Ubuntu allows you to configure network settings either through Netplan on recent releases (18.04+) or via the legacy /etc/network/interfaces file on older systems. Editing the correct file and applying the changes correctly will give you a static IP, custom DNS, or any other network behavior you need. The process is straightforward once you know which file to edit and how to validate the syntax.

What You’ll Need

  • A terminal window (Ctrl+Alt+T).
  • sudo privileges to edit system files.
  • A text editor such as nano, vim, or gedit.
  • Knowledge of your network interface name (e.g., eth0, enp0s3).
  • Optional: a backup of the original config file.

Step‑by‑Step

  1. Open a terminal and identify the active network interface:
    ip link | grep state
    
    The interface in the "UP" state is the one you will configure. Keep its name for later steps.
  2. For Ubuntu 18.04+ (Netplan):
    sudo nano /etc/netplan/01-netcfg.yaml
    
    If the file does not exist, create it or edit an existing one in /etc/netplan/. The file should contain a structure like:
    network:
      version: 2
      renderer: networkd
      ethernets:
        enp0s3:
          dhcp4: true
    
    Replace dhcp4: true with your static configuration as shown in the next step.
  3. Configure a static IP in the Netplan file. For example:
    network:
      version: 2
      renderer: networkd
      ethernets:
        enp0s3:
          dhcp4: no
          addresses:
            - 192.168.1.100/24
          gateway4: 192.168.1.1
          nameservers:
            addresses:
              - 8.8.8.8
              - 8.8.4.4
    
    Save the file (Ctrl+O, Enter, Ctrl+X in nano).
  4. Validate the syntax before applying:
    sudo netplan try
    
    The system will apply the configuration for 120 seconds. If the network works, confirm by pressing Enter. If not, it will revert automatically. This step prevents a broken network that could lock you out.
  5. Apply the configuration permanently:
    sudo netplan apply
    
    Verify connectivity with ping -c 4 8.8.8.8 and ping -c 4 google.com. If DNS fails, double‑check the nameservers section.
  6. For older Ubuntu releases (pre‑18.04) using /etc/network/interfaces:
    sudo nano /etc/network/interfaces
    
    Add or modify a stanza such as:
    auto enp0s3
    iface enp0s3 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
    
    Restart networking:
    sudo systemctl restart networking
    
    or reboot to apply changes.

Common Mistakes

  • Using the wrong interface name (e.g., eth0 instead of enp0s3). Verify with ip link before editing.
  • Leaving a stray colon or indentation error in the YAML file. Netplan is strict about spaces; two spaces per level is recommended.
  • Forgetting to set renderer: networkd or renderer: NetworkManager when you want NetworkManager to manage the interface.
  • Applying netplan try but not confirming, causing the system to revert to the old config.
  • Editing /etc/network/interfaces on a system that uses Netplan; the changes will be ignored.

Tips

  • Always back up the original file before editing: sudo cp /etc/netplan/01-netcfg.yaml /etc/netplan/01-netcfg.yaml.bak.
  • Use sudo netplan --debug apply to see detailed output if the apply fails.
  • When configuring multiple interfaces, keep each under its own key in the YAML file to avoid conflicts.
  • If you use NetworkManager for Wi‑Fi, keep renderer: NetworkManager and edit the Wi‑Fi settings via the GUI instead of Netplan.
  • For IPv6, add a addresses: block with a /64 prefix and a gateway6: entry.

Troubleshooting

When the network does not come up after editing, follow these steps:

  • Check the syntax with sudo netplan try or sudo netplan --debug apply. Errors will be printed to the console.
  • Review the system journal for networkd messages: journalctl -u systemd-networkd or journalctl -u NetworkManager.
  • Verify the interface is not blocked by a firewall rule or ufw. Disable temporarily with sudo ufw disable to test.
  • If the interface shows as DOWN, check the cable or switch port. Use sudo dmesg | grep enp0s3 for hardware errors.
  • For DHCP failures, confirm the DHCP server is reachable and not denying the MAC address. Use sudo dhclient -v enp0s3 to force a request.
  • If DNS does not resolve, test with dig @8.8.8.8 google.com to see if the nameserver is reachable.
  • When unsure, revert to the backup file and run sudo netplan apply again.

Frequently Asked Questions

How do I find my interface name?

Run ip link | grep state or ifconfig -a to list all interfaces. The one marked UP is usually the active one.

Can I use Netplan with NetworkManager?

Yes, set renderer: NetworkManager in the YAML file. NetworkManager will then manage the interface while Netplan handles the initial configuration.

What happens if I forget to run netplan apply?

The changes are not applied until the command is executed. The system will continue using the previous configuration.

Is it safe to edit /etc/network/interfaces on 20.04?

No. Ubuntu 20.04 and newer use Netplan by default. Editing /etc/network/interfaces will have no effect unless Netplan is disabled.

How do I revert a broken Netplan configuration?

Use the backup file you created earlier: sudo cp /etc/netplan/01-netcfg.yaml.bak /etc/netplan/01-netcfg.yaml and then sudo netplan apply.