Network interfaces in Ubuntu Server are managed primarily through the Netplan configuration system, which translates human-readable YAML files into low-level backend configurations for either NetworkManager or systemd-networkd. Understanding this layer is essential for configuring static IPs, bondings, and VPN tunnels correctly without relying on deprecated ifupdown scripts.
Understanding the Netplan Architecture
Ubuntu Server 18.04 and later versions utilize Netplan as the default network configuration utility. This tool acts as an abstraction layer that generates configuration for lower-level network managers. By default, modern Ubuntu installations use
systemd-networkd as the backend, although
NetworkManager remains a supported alternative, particularly for desktop hybrids or specific server deployments requiring dynamic host management.
The core principle of Netplan is declarative configuration. You define what the network state should look like in a YAML file, rather than issuing imperative commands to change the state immediately. These configuration files are stored in the
/etc/netplan/ directory. When you modify these files, you must apply them using the
netplan apply command, which validates the syntax and pushes the changes to the backend manager.
Locating Configuration Files
To inspect your current network setup, list the files in the configuration directory:
ls -l /etc/netplan/
You will typically see a single YAML file, such as
00-installer-config.yaml or
50-cloud-init.yaml. The number prefix indicates priority; however, in most standard server installations, there is only one active file. Editing these files requires root privileges, so always use a secure editor like
nano or
vim with
sudo.
Basic Interface Configuration
A basic network interface definition includes the device name, IP address assignment method, and gateway settings. Below is a standard example for a static IPv4 configuration on an Ethernet interface named
eth0.
network:
version: 2
ethernets:
eth0:
dhcp4: no
addresses:
- 192.168.1.10/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 1.1.1.1
In this snippet,
dhcp4: no disables automatic IP acquisition. The
addresses field specifies the static IP and subnet mask. The
routes section defines the default gateway, which is crucial for external connectivity. Finally, the
nameservers block configures DNS resolution, ensuring that domain names resolve to IP addresses.
If you prefer DHCP, you can simplify the configuration by setting
dhcp4: yes and omitting the static IP, routes, and nameserver blocks, allowing the router to handle those assignments automatically.
Advanced Networking: Bonding and VLANs
For high-availability setups, Linux supports network bonding, which combines multiple physical interfaces into a single logical interface. This provides load balancing and fault tolerance. Netplan supports bonding through the
bonding type in the YAML structure.
Similarly, Virtual LANs (VLANs) allow you to segment traffic on a single physical link. In Netplan, you define VLANs under the parent interface using the
vlan key. This is particularly useful in data center environments where network isolation is required without additional hardware switches.
When configuring complex topologies, ensure that the backend manager (
systemd-networkd or
NetworkManager) supports the specific features you intend to use. While both support basic IPv4/IPv6, some advanced bonding modes or VLAN tagging behaviors may have subtle differences in implementation.
Troubleshooting Common Issues
Network misconfigurations can lead to loss of SSH access, making remote troubleshooting difficult. Always verify your configuration syntax before applying it. Use
netplan generate to check for errors without applying changes. If the command returns no output, the syntax is valid.
If you lose connectivity after applying a new configuration, revert to the previous state by restoring the original YAML file from backup or using the cloud-init cache if available. For immediate diagnostics, use
ip addr show to verify interface states and
ip route to check routing tables.
For VPN integration, such as WireGuard or OpenVPN, the network interface handling depends on the tunnel type. WireGuard creates virtual interfaces that route traffic through existing physical interfaces. If you encounter issues with internal network access while connected to a VPN, consult our guide on
Routing Internet-Bound Traffic Between Two WireGuard Peers to adjust routing tables properly.
Another common issue arises when VPN clients do not receive correct DNS or gateway routes. Ensure that your VPN configuration explicitly sets the
route and
dns parameters within the client configuration file. If you are setting up a new VPN connection from scratch, refer to
How to Set Up a VPN on Linux Using OpenVPN: A Comprehensive Guide for detailed steps on daemon configuration and service management.
Verifying Connectivity and Services
After applying changes, verify that the network service is running correctly. For
systemd-networkd, use
systemctl status systemd-networkd. Check the journal logs for any errors related to interface initialization:
journalctl -u systemd-networkd -f
This real-time log view helps identify why an interface might fail to come up. Common causes include incorrect MAC addresses, conflicting IP ranges, or missing gateway definitions.
If you are connecting directly to a router without intermediate switches, ensure that the interface is set to accept traffic correctly. Misconfigured direct links often result in ping failures despite correct IP settings. Reviewing
Configure Ethernet Interface for Direct Link with Computer Router to Internet on Jetson Nano (Ubuntu 22.04) can provide insights into handling direct physical connections where NAT is not involved.
Frequently Asked Questions
How do I switch from NetworkManager to systemd-networkd?
You can switch backends by modifying the
renderer field in your Netplan YAML file. Change
renderer: NetworkManager to
renderer: systemd-networkd and run
netplan apply. Note that NetworkManager may need to be stopped or disabled to prevent conflicts.
Why does netplan apply fail with a syntax error?
YAML is sensitive to indentation and spacing. Ensure you use spaces, not tabs, and maintain consistent indentation levels. Use
netplan generate to pinpoint the exact line causing the error before attempting to apply the configuration again.
Can I configure multiple network interfaces in one file?
Yes, you can define multiple interfaces under the
ethernets,
wifis, or other relevant sections in a single YAML file. Each interface is defined by its unique name, allowing centralized management of complex network setups.
What happens if I lose SSH access after changing network settings?
If you lose access, you will need physical console access or out-of-band management to revert the changes. Restore the original configuration file from a backup or reinstall the package if necessary. Always test changes in a non-production environment first.
How do I disable IPv6 on a specific interface?
Add
ipv6: false under the specific interface configuration in Netplan. This disables IPv6 stack initialization for that interface. Alternatively, you can use sysctl settings in
/etc/sysctl.conf for a global disable, though per-interface control is preferred for servers.