As you may have noticed, the network configuration in Ubuntu 18.04 has changed. /etc/network/interfaces is not used anymore.
We’ll see how to configure network interfaces from command line in Ubuntu 18.04 and derivatives.
This is what we will learn:
- Netplan tool and configuration files.
- Modify configuration yaml file, a few examples.
- Apply modified network settings.
This article applies to network configuration through networkd, which is going to be specially usefull for command line setup.
If you are on a desktop environment, you probably have network-manager installed, so just config your network interfaces using the network graphic tool.
Netplan tool and configuration files
The tool we have to use now is “netplan”.
This tools uses a different network configuration files, the new files are under /etc/netplan, there you can find a “YAML” file.
If there are no files there, or you need to create them, you can generate them with:
Modifying configuration yaml file, a few examples
This is how my VM test config file /etc/netplan/01-netcfg.yaml looks like:
network: version: 2 renderer: networkd ethernets: enp0s3: dhcp4: yes enp0s8: dhcp4: no dhcp6: no addresses: [192.168.56.23/24]
We can easily find the patern here.
Lets see 2 typical examples.
Static IP with gateway and DNS
In this example, IP:192.168.56.23 and netmask 255.255.255.0, gateway:192.168.56.1 and DNS servers:192.168.56.1 and 188.8.131.52.
network: version: 2 renderer: networkd ethernets: enp0s3: dhcp4: no dhcp6: no addresses: [192.168.56.23/24] gateway4: 192.168.56.1 nameservers: addresses: [192.168.56.1,184.108.40.206]
Dynamic IP – DHCP
Automatic config with DHCP:
network: version: 2 renderer: networkd ethernets: enp0s3: dhcp4: yes
Applying modified network settings
There are two ways to do this: using netplan tool or restarting networkd daemon.
sudo netplan apply
Restarting networkd daemon
systemctl status systemd-networkd