C²S Consulting logo
C²S Consulting | Primers | netplan networking

netplan, networking in Ubuntu 17.10, Artful Ardvark

netplan is the new Yet Another Markup Language (YAML) network configuration abstraction for various backends that replaces ifupdown with the Ubuntu 17.10,codename: Artful Ardvark release.

It is particularly useful to understand how netplan works if you arte configuring servers.

During boot, the netplan network renderer, systemd networkd runs which reads the /etc/netplan/*.yaml files and uses /lib/netplan/generate to generate backend network configuration files from the YAML definitions in /run/systemd/network/*.

By default the renderer is set to systemd networkd but it can be set to NetworkManager which is typical of laptops and mobile devices.

The /etc/network/interfaces file

The /etc/network/interfaces file is essentially redundant as there is no ifupdown tools to configure network interfaces from it. The file should look like this.

ubuntu@ub-17-10:~$ cat /etc/network/interfaces
# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
# Generated by debian-installer.

# The loopback interface
auto lo
iface lo inet loopback

The /etc/netplan/01-netcfg.yaml file

The /etc/netplan/01-netcfg.yaml file uses the YAML version 2 syntax. Here is a basic configuration which uses Dynamic Host Configuration Protocol (DHCP) to configure the interfaces.

ubuntu@ub-17-10:~$ cat /etc/netplan/01-netcfg.yaml
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s25:
      dhcp4: true
      dhcp6: true

ubuntu@ub-17-10:~$ sudo netplan apply

ubuntu@ub-17-10:~$ ip address list

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:74:7a:3c brd ff:ff:ff:ff:ff:ff
    inet 192.168.89.3/24 brd 192.168.89.255 scope global dynamic enp0s25
       valid_lft 570sec preferred_lft 570sec
    inet6 2a92:168:89::a00:27ff:fe74:7a3c/64 scope global 
       valid_lft 570sec preferred_lft 570sec
    inet6 fe80::a00:27ff:fe74:7a3c/64 scope link 
       valid_lft forever preferred_lft forever

A fixed IP address

A typical server task is to set a fixed IP address with a default gateway and a DNS Server. Here is an example.

ubuntu@ub-17-10:~$ sudo vi /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s25:
      addresses: ['192.168.89.220/24','2a92:168:89::220/64']
      gateway4: 192.168.89.1
      gateway6: 2a92:168:89::1
      nameservers:
        search: ['netlabsug.tst']
        addresses: ['192.168.89.201','8.8.8.8']

ubuntu@ub-17-10:~$ sudo netplan apply

ubuntu@ub-17-10:~$ ip address list
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:74:7a:3c brd ff:ff:ff:ff:ff:ff
    inet 192.168.89.220/24 brd 192.168.89.255 scope global enp0s25
       valid_lft forever preferred_lft forever
    inet6 2a92:168:89::220/64 scope global 
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe74:7a3c/64 scope link 
       valid_lft forever preferred_lft forever

A more complex example

netplan is capable of quite complex configurations. Take this example where the interface enp0s25 is setup as a Virtual Local Area Network (VLAN) trunk with two VLANs, vlan100 and vlan200. Each of these VLANs are connected to internal bridges br100 and br200 which could be used for connecting Virtual Machines (VM) or to other physical interfaces, in the example below enp3s0f0 and enp3s0f1 become part of br100 and vlan100 while enp4s0f0 and enp4s0f1 become part of br200 and vlan200.

ubuntu@ub-17-10:~$ cat /etc/netplan/01-netcfg.yaml
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s25:
      dhcp4: false
      dhcp6: false
    enp3s0f0:
      dhcp4: false
      dhcp6: false
    enp3s0f1:
      dhcp4: false
      dhcp6: false
    enp4s0f0:
      dhcp4: false
      dhcp6: false
    enp4s0f1:
      dhcp4: false
      dhcp6: false
  vlans:
    vlan100:
      id: 100
      link: enp0s25
    vlan200:
      id: 200
      link: enp0s25
  bridges:
    br100:
      addresses: ['199.9.9.100/24','2a99:9:9::100/64']
      interfaces: ['vlan100', 'enp3s0f0', 'enp3s0f1']
      parameters:
        forward-delay: 9
        hello-time: 2
        max-age: 12
        stp: false
    br200:
      addresses: ['192.168.92.200/24','2a92:168:92::200/64']
      gateway4: 192.168.92.1
      gateway6: 2a92:168:92::1
      nameservers:
        search: ['netlabsug.tst']
        addresses: ['192.168.92.201', '8.8.8.8']
      interfaces: ['vlan200', 'enp4s0f0', 'enp4s0f1']
      parameters:
        forward-delay: 9
        hello-time: 2
        max-age: 12
        stp: false


ubuntu@ub-17-10:~$ sudo netplan apply

ubuntu@ub-17-10:~$ ip address list
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:1c:c0:35:a5:fb brd ff:ff:ff:ff:ff:ff
    inet6 fe80::21c:c0ff:fe35:a5fb/64 scope link 
       valid_lft forever preferred_lft forever
3: enp3s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br100 state UP group default qlen 1000
    link/ether 00:15:17:76:82:94 brd ff:ff:ff:ff:ff:ff
4: enp3s0f1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br100 state UP group default qlen 1000
    link/ether 00:15:17:76:82:95 brd ff:ff:ff:ff:ff:ff
5: enp4s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br200 state UP group default qlen 1000
    link/ether 00:15:17:76:82:96 brd ff:ff:ff:ff:ff:ff
6: enp4s0f1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br200 state UP group default qlen 1000
    link/ether 00:15:17:76:82:97 brd ff:ff:ff:ff:ff:ff
7: br100: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 0e:c7:b2:c0:61:85 brd ff:ff:ff:ff:ff:ff
    inet 199.9.9.100/24 brd 199.9.9.255 scope global br100
       valid_lft forever preferred_lft forever
    inet6 2a99:9:9::100/64 scope global 
       valid_lft forever preferred_lft forever
    inet6 fe80::cc7:b2ff:fec0:6185/64 scope link 
       valid_lft forever preferred_lft forever
8: br200: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether ca:47:95:0d:e5:35 brd ff:ff:ff:ff:ff:ff
    inet 192.168.92.200/24 brd 192.168.92.255 scope global br200
       valid_lft forever preferred_lft forever
    inet6 2a92:168:92::200/64 scope global 
       valid_lft forever preferred_lft forever
    inet6 fe80::c847:95ff:fe0d:e535/64 scope link 
       valid_lft forever preferred_lft forever
9: vlan100@enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br100 state UP group default qlen 1000
    link/ether 00:1c:c0:35:a5:fb brd ff:ff:ff:ff:ff:ff
    inet6 fe80::21c:c0ff:fe35:a5fb/64 scope link 
       valid_lft forever preferred_lft forever
10: vlan200@enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br200 state UP group default qlen 1000
    link/ether 00:1c:c0:35:a5:fb brd ff:ff:ff:ff:ff:ff
    inet6 fe80::21c:c0ff:fe35:a5fb/64 scope link 
       valid_lft forever preferred_lft forever

Copyright © 2024 C²S Consulting