Network interface configuration in Ubuntu 18.04 via netplan
Network configuration in Ubuntu 18.04 has been changed quite a lot compared to previous versions of Ubuntu. The configuration file /etc/network/interfaces has not gone away, but it has become insignificant, now it contains only the text that files related to network settings are now located in the /etc/netplan directory:
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 apply
Network 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
This article describes two ways to configure a network in Ubuntu 18.04, both with and without netplan.