Network interface configuration in Ubuntu 18.04 via netplan
Network management in Ubuntu 18.04 has undergone significant changes compared to earlier releases. While the traditional configuration file /etc/network/interfaces still exists, it now plays a minimal role, serving mainly as a reference. The actual network settings are now managed through YAML files located in the /etc/netplan directory, which have become the primary method for defining and controlling network interfaces:

Let's look at this:
ls /etc/netplan
Then take a look at the file structure:
cat /etc/netplan/50-cloud-init.yaml
The netplan settings is described in YAML (Yet Another Markup Language). Let's look inside:
- network — a "marker" word that means the start of a logical block of the settings;
- ethernets — this parameter means that the Ethernet network will be configured further;
- enp0s3 — the name of the interface to be setup. Yours will probably look different. All network interfaces present on the computer will be displayed after the following command:
ifconfig -a- addresses — an IP addresses that the interface has. Addresses should be set in CIDR format. The first IP is written as at the screenshot, and when more than one address is required, they are placed in square brackets, a comma is placed between the addresses;
- gateway4 — IPv4 gateway;
- nameservers — this "marker" indicates that the section below contains the names or IP-addresses of servers that processes DNS queries;
- addresses — names (or addresses) of hosts that resolve DNS names to IP addresses. If necessary, they may be written in square brackets as described above, one address is separated from another by a comma;
- version — YAML language version.
To activate new settings, run this:
netplan applyNetwork configuration without netplan
Before the setup, I advice you to clarify which interfaces are really present in the system:
ifconfig -a
In the screenshot above, you can see that there are two interfaces without assigned IP's present, cause the machine is waiting for settings from the DHCP server. In a situation where there is no such DHCP-server in the network segment, you should assign the IP manually. So, change the config-file so that it looks like the one shown in the picture:
sudo nano /etc/network/interfaces
Let's talk about the parameters:
- auto enp0s3 - this instruction "tells" the computer to automatically start the network after reboot;
- iface enp0s3 inet static - parameter indicating that the network address should be set manually;
- address 10.10.2.6 - assigned IPv4 address;
- netmask 255.255.255.0 - subnet mask
- gateway 10.10.2.1 - IPv4 gateway
- dns-nameservers 8.8.8.8 - hosts that process DNS requests.
To confirm the changes, you should run this:
sudo /etc/init.d/networking restart
After the service restart, the computer should be available via assigned IP address. If not, reboot the server entirely, it will help.
Conclusion
In this guide, we explored two approaches for configuring network interfaces in Ubuntu 18.04: using Netplan and the traditional /etc/network/interfaces method. Netplan provides a modern, YAML-based configuration system that integrates seamlessly with NetworkManager and systemd-networkd, making it easier to manage network settings. At the same time, the classic method remains available for scenarios where manual static configuration is required or DHCP is not accessible. By understanding both approaches, you can confidently manage and troubleshoot network connectivity on Ubuntu servers, ensuring stable and reliable access for your system and applications.
FAQ
- Q1: What is Netplan and why is it used in Ubuntu 18.04?
A1: Netplan is a YAML-based network configuration tool introduced in Ubuntu 17.10. It allows administrators to define network interfaces and settings in a simple, structured way, working with NetworkManager or systemd-networkd as backends. - Q2: How can I check which network interfaces are available on my Ubuntu server?
A2: Use the command ifconfig -a or ip addr show to list all available network interfaces, including those without assigned IP addresses. - Q3: How do I apply changes made to Netplan configuration files?
A3: After editing a YAML file in /etc/netplan/, run sudo netplan apply to apply the new network settings immediately. - Q4: How can I manually assign a static IP without Netplan?
A4: Edit /etc/network/interfaces with the desired IP, netmask, gateway, and DNS entries, then restart the networking service using sudo /etc/init.d/networking restart. - Q5: What should I do if network changes don’t take effect immediately?
A5: Ensure the configuration syntax is correct. If the issue persists, restart the network service or reboot the server to apply settings.