Skip to main content

Netplan, Bonding, and VLANs

Creating 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:
      dhcp4: no
      optional: true
    enp2s0:
      dhcp4: no
      optional: true
    # match all other ports if desired
    ethernetPorts:
      dhcp4: no
      optional: true
      match:
        name: eth*|em*|en*
  bonds:
    bond0:
      interfaces: [ enp1s0, enp2s0enp2s0, ethernetPorts ]
      addresses: [ 192.168.168.115/24 ]
      gateway4: 192.168.168.1
      nameservers:
        search: [ mydomain.com ]
        addresses: -[ "192.168.168.1, 8.8.8.8"8, - "8.8.4.4"4 ]
      parameters:
        mode: active-backup
        primary: enp1s0
        primary-reselect-policy: always
        mii-monitor-interval: 100
        up-delay: 100003s # must be a multiple of mii-monitor-interval, make sure its longer than STP/RSTP/MSTP learning interval also
#      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:
      dhcp4: no
      optional: true
    enp2s0:
      dhcp4: no
      optional: true
    # match all other ports if desired
    ethernetPorts:
      dhcp4: no
      optional: true
      match:
        name: eth*|em*|en*
  bonds:
    bond0:
      interfaces: [ enp1s0, enp2s0, ethernetPorts ]
      addresses: [ 192.168.168.115/24 ]
      interfaces: [ enp1s0, enp2s0 ]
      parameters:
        mode: active-backup
        primary: enp1s0
        primary-reselect-policy: always
        mii-monitor-interval: 100
        up-delay: 100003s # must be a multiple of mii-monitor-interval, make sure its longer than STP/RSTP/MSTP learning interval also
#      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: -[ "1.1.1.113, 8.8.8.8"8, - "8.8.4.4"4 ]

systemd-networkd-wait-online.service

Ubuntu 22.04

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 as shown below. You can also reduce the default timeout from 120 seconds to 10 seconds by adding the "--timeout=10" option.

On Ubuntu, the file is located at /etc/systemd/system/
On Debian, the file is located at /var/lib/systemd/system/

[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.

Debian 11 (Raspberry Pi)

On a Raspberry Pi running Debian 11.5, we had a similar issue. We never were able to get rid of the message, but making the above configuration changes made sure the system booted properly regardless of how many Ethernet interfaces were physically connected to switches at boot time.

Error during boot:

[FAILED] Failed to start Wait for Network to be Configured.
See 'systemctl status systemd-networkd-wait-online.service' for details.

Output from systemctl status commands:

# OUTPUT FROM systemctl status systemd-networkd-wait-online.service
    systemd-networkd-wait-online.service - Wait for Network to be Configured
     Loaded: loaded (/lib/systemd/system/systemd-networkd-wait-online.service; enabled-runtime; vendor preset: disabled)
     Active: failed (Result: exit-code) since Thu 2023-05-18 17:10:59 BST; 2min 44s ago
       Docs: man:systemd-networkd-wait-online.service(8)
    Process: 189 ExecStart=/lib/systemd/systemd-networkd-wait-online (code=exited, status=1/FAILURE)
   Main PID: 189 (code=exited, status=1/FAILURE)
        CPU: 148ms

Aug 07 14:25:36 6230dea99f07e90f52b5f68b systemd[1]: Starting Wait for Network to be Configured...
May 18 17:10:59 6230dea99f07e90f52b5f68b systemd-networkd-wait-online[189]: Event loop failed: Connection timed out
May 18 17:10:59 6230dea99f07e90f52b5f68b systemd[1]: systemd-networkd-wait-online.service: Main process exited, code=exited, status=1/FAILURE
May 18 17:10:59 6230dea99f07e90f52b5f68b systemd[1]: systemd-networkd-wait-online.service: Failed with result 'exit-code'.
May 18 17:10:59 6230dea99f07e90f52b5f68b systemd[1]: Failed to start Wait for Network to be Configured.

References

https://netplan.io/examples

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