I want to switch to systemd and with this I have to setup the linux bridge for my virtual machines in KVM to use VLAN.
Having Debian GNU/Linux 9.1 (stretch), using its systemd-networkd and libvirt. NOT using oldstyle networking with ifupdown
(deinstalled it).
I'm sitting on harley, my all day workstation for testing and setup the bridge on the host.
harley$ cat /etc/systemd/network/08-br0.netdev
[NetDev]
Name=br0
Kind=bridge
[Bridge]
VLANFiltering=true
STP=false
harley$ cat /etc/systemd/network/12-br0_add-enp1s0.network
[Match]
Name=enp1s0
[Network]
Bridge=br0
[BridgeVLAN]
VLAN=10
[BridgeVLAN]
VLAN=20
[BridgeVLAN]
VLAN=30
harley$ cat /etc/systemd/network/16-br0_up.network
[Match]
Name=br0
Cleanup an old bridge from testing and setup a new one from scratch:
harley$ sudo ip link set dev br0 down && sudo ip link del dev br0
harley$ sudo systemctl restart systemd-networkd
harley$
It's all in place now:
harley$ cat /sys/class/net/br0/bridge/vlan_filtering
1
harley$ cat /sys/class/net/br0/bridge/stp_state
0
harley$ sudo bridge vlan show
port vlan ids
enp1s0 1 PVID Egress Untagged
10
20
30
br0 1 PVID Egress Untagged
harley$
Now I start the virtual machine, login and show its interface setting:
harley$ virsh start --console deb9-test
login
deb9-test$ cat /etc/systemd/network/08-vlan10.netdev
[NetDev]
Name=vlan10
Kind=vlan
[VLAN]
Id=10
deb9-test$ cat /etc/systemd/network/12-vlan10_attach-to-if.network
[Match]
Name=ens2
[Network]
VLAN=vlan10
deb9-test$ cat /etc/systemd/network/16-vlan10_up.network
[Match]
Name=vlan10
[Network]
Address=192.168.10.57/24
Gateway=192.168.10.1
DNS=192.168.10.8
But pinging the gateway gives no result at this stage:
deb9-test$ ping -c1 192.168.10.1
PING 192.168.10.1 (192.168.10.1) 56(84) bytes of data.
From 192.168.10.57 icmp_seq=1 Destination Host Unreachable
--- 192.168.10.1 ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms
The bridge shows now:
harley$ sudo bridge vlan show
port vlan ids
enp1s0 1 PVID Egress Untagged
10
20
30
br0 1 PVID Egress Untagged
vnet0 1 PVID Egress Untagged
I have to modify it:
harley$ sudo bridge vlan del dev enp1s0 vid 1
harley$ sudo bridge vlan del dev br0 vid 1 self
harley$ sudo bridge vlan del dev vnet0 vid 1
harley$ sudo bridge vlan add vid 10 dev vnet0
VM works now:
deb9-test$ ping -c1 192.168.10.1
PING 192.168.10.1 (192.168.10.1) 56(84) bytes of data.
64 bytes from 192.168.10.1: icmp_seq=1 ttl=64 time=0.843 ms
--- 192.168.10.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.843/0.843/0.843/0.000 ms
After modification this is what I want, simple and clean:
harley$ sudo bridge vlan show
port vlan ids
enp1s0 10
20
30
br0 None
vnet0 10
And finaly now my Question:
how can I make Debian to do this for me right up before the VMs interface comes up, so it can get its ip-address with DHCP?
[VLAN] \ Id=10
to08-br0.netdev
Kind=bridge
systemd.netdevOpen vSwitch
better scale together withsystemd-networkd
andlibvirt
?