Skip to main content

Netplan, Bonding, and VLANs

ExampleCreating a bond interface with Netplan

The example below shows two Ethernet interfaces bonded using the active-passive mode.

The following packages are required: ifenslave and vlan

network:
  version: 2
  ethernets:
    enp1s0:
      optional: true
    enp2s0:
      optional: true
  bonds:
    bond0:
      interfaces: [ enp1s0, enp2s0 ]
      addresses: [ 192.168.168.115/24 ]
      gateway4: 192.168.168.1
        nameservers:
            search: [ mydomain.com ]
            addresses:
            - "8.8.8.8"
            - "8.8.4.4"
      parameters:
        mode: active-backup
        primary: enp1s0
        mii-monitor-interval: 100
        up-delay: 10000 # must be a multiple of mii-monitor-interval
#      routes:
#        - to: 10.0.0.0/8
#          via: 192.168.168.1
#        - to: 172.16.0.0/12
#          via: 192.168.168.1
#        - to: 192.168.0.0/16
#          via: 192.168.168.1

Notes:

  • "optional: true" instructs Netplan to boot the operating system even if the network interface is unavailable or not connected or unavailable. Without this option, the system will not fully boot until all network cables are connected.
  • "mii-monitor-interval: 100" must be set to some value or link up / down events will not actually be detected. A value of zero, which is the default, will disable the detection of interface changes, which seems rather counter-intuitive when we're configuring the mode as active-backup.
  • "up-delay: 10000" prevents packet loss when connecting an interface. It must be a multiple of the mii-monitor-interval value.

Using a VLAN on a bond interface

This is a configuration using from Ubuntu 18.04 LTS. Two Ethernet interfaces are bonded using the active-passive mode. The untagged bond0 interface is for private traffic, while a public IP address is being delivered to a tagged VLAN sub interface using VLAN 262.

The following packages are required: ifenslave and vlan

network:
  version: 2
  ethernets:
    enp1s0:
      optional: true
    enp2s0:
      optional: true
  bonds:
    bond0:
      addresses: [ 192.168.168.115/24 ]
      interfaces: [ enp1s0, enp2s0 ]
      parameters:
        mode: active-backup
        primary: enp1s0
        mii-monitor-interval: 100
        up-delay: 10000 # must be a multiple of mii-monitor-interval
#      routes:
#        - to: 10.0.0.0/8
#          via: 192.168.168.1
#        - to: 172.16.0.0/12
#          via: 192.168.168.1
#        - to: 192.168.0.0/16
#          via: 192.168.168.1
  vlans:
    bond0.262:
        id: 262
        link: bond0
        addresses: [ 1.1.1.123/28 ]
        gateway4: 1.1.1.113
        nameservers:
            search: [ servers.domain.com ]
            addresses:
            - "8.8.8.8"
            - "8.8.4.4"

systemd-networkd-wait-online.service

In Ubuntu 22.04, even though the netplan configuration is correct, the service systemd-networkd-wait-online.service will wait for 120 seconds if one of the network interfaces is not connected.

In order to get around this, one solution is to add the "--any" option to the ExecStart line:line as shown below. You can also reduce the default timeout from 120 seconds to 10 seconds by adding the "--timeout=10" option.

[Unit]
Description=Wait for Network to be Configured
Documentation=man:systemd-networkd-wait-online.service(8)
DefaultDependencies=no
Conflicts=shutdown.target
Requires=systemd-networkd.service
After=systemd-networkd.service
Before=network-online.target shutdown.target

[Service]
Type=oneshot
ExecStart=/lib/systemd/systemd-networkd-wait-online --any --timeout=10
RemainAfterExit=yes

[Install]
WantedBy=network-online.target

Alternatively, you could just disable and mask the service altogether as it actually isn't needed. If you are going to disable the service, I would strongly recommend adding the two options shown above in addition just in case the service gets re-enabled in the future.

References

https://www.freedesktop.org/software/systemd/man/systemd-networkd-wait-online.service.html