How to configure systemd to bring up a virtual network interface from a vlan trunk.

Prerequisite

  • Debian 9 (aka Stretch) or probably most of the systemd installations.
  • Knowledge of how to manage network setup with systemd. [1]
  • No other managers for the network, like network-manager, ifup/down etc.
  • Trunked connection to an ethernet card. Here I suppose to have vlan id 10 and 20 trunked to the eno1 network card.

Scope

Extract from the network interface eno1 the two vlans (10, 20) and configure the 1st vlan (10) with a standard ipv4 address which bringing up the second vlan for other use, for example libvirt, kvm or other stuff.

note: You may require to setup a bridge on top of the vlan (eno1.20) for multiple virtual machine connected on it .

eno1 configuration

This is the configuration of the physical network card. Here we define only the presence of the two vlans.

/etc/systemd/network/eno1.network

[Match]
Name=eno1

[Network]
VLAN=eno1.10
VLAN=eno1.20

Vlan10 configuration

This is the working interface for the server with IP address etc.

/etc/systemd/network/eno1.10.netdev

[NetDev]
Name=eno1.10
Kind=vlan

[VLAN]
Id=10

/etc/systemd/network/eno1.10.network

[Match]
Name=eno1.10

[Network]
Description="VLAN 10"
Address=10.0.0.10/24
Gateway=10.0.0.1
DNS=8.8.8.8
DNS=10.0.0.100
Domains=example.com
NTP=myntp.example.com

Vlan 20 configuration

This instead is the definition of the vlan interface that need to be bring UP with the eno1 interface and be available for other used non-systemd managed.

/etc/systemd/network/eno1.20.netdev

[NetDev]
Name=eno1.20
Kind=vlan

[VLAN]
Id=20

In this config file we define that the Link is unmanaged by systemd and that the network link will follow (BindCarrier) the status of the real interface eno1.

/etc/systemd/network/eno1.20.network

[Match]
Name=eno1.20

[Link]
Unmanaged="yes"

[Network]
Description="VLAN 20"
BindCarrier=eno1

References:

-> Send a comment: Unless requested otherwise I may add it, or some extract, to this page.