Modern versions of Ubuntu offer many different ways to configure network settings, and it’s easy to get confused. In this article, we will have a look at how to configure network settings in Ubuntu using Network Manager, Systemd Networkd, Netplan, and the static configuration file /etc/network/interfaces (legacy way).
Configure Network Settings on Ubuntu (Network Manager, Systemd and Netplan)
How to Use Network Manager on Ubuntu?
Ubuntu’s default network management tool is Network Manager. This is a universal way to configure a network for Ubuntu desktops. NM includes a graphical and nmcli
command, allowing you to conveniently work with WLAN connections, VLAN, etc.
Check that this service is running:
$ systemctl status NetworkManager
The Network Manager configuration file is /etc/NetworkManager
. Connection settings are stored in the system-connections
directory. To configure the network parameters, you can use the nmcl command or the pseudo-graphical interface of the Network Manager TUI.
$ sudo nmtui
List network interfaces:
$ nmcli device
List all interface network settings:
$ nmcli
Specific network interface settings:
$ nmcli device show ens33
Use nmcli to configure a static IP address for the interface:
$ sudo nmcli con mod ens33 ipv4.addresses 192.168.55.140/24
$ sudo nmcli con mod ens33 ipv4.gateway 192.168.55.1
$ sudo nmcli con mod ens33 ipv4.dns "8.8.8.8"
Apply network settings:
$ nmcli con up ens33
Enable/disable interface:
$ nmcli connection down my_ethernet
Ubuntu Network Configuration with systemd-networkd
With systemd, you can use the systemd-networkd service to configure your network settings. It is lighter and faster than Network Manager and is recommended for use on Ubuntu servers.
First, disable applying network settings from the /etc/network/interfaces file. Just rename the file:
$ sudo mv /etc/network/interfaces /etc/network/interfaces.save
The /etc/systemd/network
directory contains the systemd-networkd.service configuration files.
Here you can create one of three file types:
*.link
– sets interface physical settings (name, MAC, MTU, etc.)*.network
– network settings (DHCP/static IP, MAC, MTU, routes, DNS)*.netdev
– configure virtual interfaces (VLAN, bridges, tunnels, VPN, etc.)
Example configuration file for the eth0 interface to get network settings from the DHCP server:
$ sudo mcedit /etc/systemd/network/mylan.network
[Match]
Name=eth0
[Network]
DHCP=ipv4
LinkLocalAddressing=no
If the host has more than one network interface, you can specify eth*
here.
Static IP configuration example:
[Match]
Name=enp8s0
[Network]
Description=Local network
Address=192.168.55.25/24
Gateway=192.168.55.1
DNS=192.168.55.1 192.168.155.1
Domains=poweradm.com
LinkLocalAddressing=no
Enable the systemd-networkd service:
$ sudo systemctl enable systemd-networkd.service
$ sudo systemctl start systemd-networkd
Check network interface status:
$ networkctl list
List network settings:
$ networkctl status
Check the systemd-networkd log:
$ journalctl -u systemd-networkd.service
Configuring Networking on Ubuntu with Netplan
Netplan adds a new layer of abstraction on top of the Ubuntu network manager. The configuration files can be found in the /etc/netplan
directory.
Ubuntu Desktop has the following default config file:
$ cat /etc/netplan/01-network-manager-all.yaml
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
The renderer: NetworkManager directive specifies that Network Manager is used to manage the network.
To obtain the network settings from the DHCP server for the enp0s3 interface, use the configuration:
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: yes
Set static IP address:
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: no
addresses: [192.168.1.10/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
Netplan allows you to check the network settings before applying them:
$ sudo netplan try
Apply new network configuration:
$ sudo netplan apply
Using /etc/network/interfaces Configuration on Ubuntu
The classic way to configure network settings in Ubuntu is to use the /etc/network/interfaces file.
In the easiest case, if you want to get all your network settings from DHCP, you need to set this here:
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
iface
– network interface nameinet
–IPv4 protocollo
– loopback interfaceauto eth0
– enable interface on boot
If you need to set a static IP:
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.55.100
netmask 255.255.255.0
gateway 192.168.55.1
dns-nameservers 8.8.8.8 8.8.4.4
You must restart the service after making the changes:
$ sudo systemctl restart networking.service
Use the ifup and ifdown commands to enable/disable the network interface:
$ sudo ifdown enp7s0
$ sudo ifup enp7s0