Configuring the network interface in Ubuntu 18.04

Ekaterina Neverova
July 13, 2020

Configuring the network interface in Ubuntu 18.04 was a surprise to many. Although there exists, familiar to all, the configuration file /etc/network/interfaces, it says:

Configuration via ifupdown has been replaced by netplan. Configuration via/etc/netplan. If you want to go back to ifupdown configure via command:

sudo apt install ifupdown

We will not install anything else. Set up what there is. First, look at the content of the directory /etc/netplan.

Let’s see, what is in this file.

The configuration file is written in YAML. The settings shown in the example above were made at the stage of installing the operating system. Let’s take a closer look.

  • network — beginning of the network configuration block;
  • ethernets — this parameter reports that the next step will be to configure the protocol of the same name;
  • enp0s3 — the name of the configurable network interface. It is likely that in your case the name will be different. A list of all interfaces can be viewed with the command ifconfig -a;
  • addresses — block of IP addresses assigned to an interface with a network prefix. One ip-address is indicated as in the example, several addresses are indicated in square brackets “[and]”, separated by commas;
  • gateway4 — IPv4 network gateway;
  • nameservers — name server configuration block.
  • addresses — it is in the nameservers block that indicate which DNS servers to access. Indicated without a network prefix. Several addresses are indicated in square brackets “[and]”, separated by commas.
  • version — YAML language version.

We activate the current settings with the command:

netplan apply

We examined the main options. More setup examples are on the official website.

What if the system does not use netplan?

It’s the old fashioned way. First we get a list of available interfaces:

ifconfig -a

In this case, there are 2 network interfaces without IP addresses (for now). Configured by DHCP. Let’s move on to the settings.

sudo nano /etc/network/interfaces

A server receiving IP from a DHCP server is not a good solution. We bring the file to the form:

What does this mean.

  • auto enp0s3 — automatic launch of a specific interface;
  • iface enp0s3 inet static — reports on static configuration;
  • address —actually, the IPv4 address for this interface;
  • netmask — netmask.
  • gateway — IPv4-gateway
  • dns-nameservers — specify DNS servers

The second and subsequent interfaces are configured in the same way or configured using a DHCP server. Apply settings:

sudo /etc/init.d/networking restart

If everything is done correctly, then we wait for the process of restarting the service.

Important. It happens that the settings file is correct, but the server does not change the IP address. In this case, restarting the server with the command helps:

sudo reboot

Let's Get It Started!
We use cookies to provide our services and for analytics and marketing. To find out more about our use of cookies, please see our Privacy Policy. By continuing to browse our website, you agree to our use of cookies.