Ubuntu: network configuration with Netplan

Since Ubuntu 17, the Linux distribution has changed the way the network is managed. Ethernet, Wifi and even loopback, Ubuntu no longer uses / etc / network / interfaces but switches to / etc / netplan / with a configuration file with the extension .yaml. A major change that must be mastered to integrate a machine on a network.

Introduced with Ubuntu 17, Netplan is therefore used by default on Ubuntu 18 LTS and Ubuntu 19. Similarly, Ubuntu 20 LTS and later will also remain with netplan.

Some Netplan configurations are offered in this tutorial but all the options are grouped together on netplan.io.

netplan ubuntu network network configuration

Open the Netplan network configuration file

Use your favorite editor to open and modify the yaml file which contains the network configuration of the Ubuntu workstation (vi, vim, emacs…).

sudo vi /etc/netplan/*.yaml

Examples of yaml file names:

  • sudo vi /etc/netplan/01-netcfg.yaml
  • sudo vi /etc/netplan/50-cloud-init.yaml

Netplan default configuration in automatic DHCP IP

It is the default content of the yaml file of an Ubuntu distribution without customization and with assignment of an IP address by a DHCP server.

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4:true

Configuration of Netplan in static IP (Ethernet)

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      addresses:
        - 10.10.10.2/24
      gateway4: 10.10.10.1
      nameservers:
          search: [mydomain, otherdomain]
          addresses: [10.10.10.1, 1.1.1.1]

Configuration of Netplan Ubuntu with a Wifi wireless network (WPA Personal)

Connection to a classic wifi, such as a box at home or a wireless access point in a hotel or restaurant (WPA Personal / WPA Personal).

network:
  version: 2
  renderer: networkd
  wifis:
    wlp2s0b1:
      dhcp4: no
      dhcp6: no
      addresses: [192.168.0.101/24]
      gateway4: 192.168.0.1
      nameservers:
        addresses: [192.168.0.1, 8.8.8.8]
      access-points:
        "network_ssid_name": SSIDwifi
          password: "clédesécuritéwifi"

Configuration of Netplan on a corporate WiFi network (WPA or WPA2 Enterprise)

Using WPA or WPA2 Enterprise security requires additional settings. For example, using WPA-EAP and TTLS.

network:
  version: 2
  wifis:
    wl0:
      access-points:
        workplace:
          auth:
            key-management: eap
            method: ttls
            anonymous-identity: "@interne.entreprise.fr"
            identity: "jean@interne.entreprise.fr"
            password: "motdepasse"
      dhcp4: yes

Netplan with a loopback interface

network:
  version: 2
  renderer: networkd
  ethernets:
    lo:
      match:
        name: lo
      addresses: [ 7.7.7.7/32 ]

Configuring Netplan for IP assignment using a Windows Server DHCP

If the default configuration does not work while your Ubuntu machine is subject to DHCP from a Windows server, it is possible to add a “dhcp-identifier” information to it for better compatibility.

network:
  version: 2
  ethernets:
    enp3s0:
      dhcp4: yes
      dhcp-identifier:mac

Save changes (important)

Do not forget to validate the modifications with the following command. This is important because even a reboot will not apply netplan changes if the “apply” is not manually forced.

sudo netplan apply

The configuration is said to be persistent, that is to say it is retained even after a restart of the system.

I don’t like Netplan

No problem, Ubuntu allows you to go back to using Network Manager.

cat /etc/network/interfaces
# ifupdown has been replaced by netplan(5) on this system. See
# /etc/netplan for current configuration.
# To re-enable ifupdown on this system, you can run:
# sudo apt install ifupdown