Day 3: Bridges, VLANs and Bonds
Goal: Attach several namespaces to a virtual switch and watch it learn MAC addresses. Separate the network with VLANs, tagged and untagged. Bundle two links into a bond and let one of them fail · Duration: approx. 90 min · Prerequisite: Day 2
Briefing
- A Linux bridge is a switch in the kernel.
Interfaces you give it as ports (
master br-lab) are like cables in a switch: whatever comes in on one port goes out on the port behind which the destination MAC sits. The bridge learns this mapping by itself, in its FDB (Forwarding Database). - A VLAN splits a cable or a switch into separate networks. On the wire, every frame carries an 802.1Q tag with the VLAN number. “Access port”: untagged, one VLAN. “Trunk”: tagged, several VLANs.
- A bond combines several interfaces into one logical
interface. In
active-backupmode, one works and the other steps in when the first one fails. - Everything today runs in namespaces and on bridges that exist only
inside the VM.
eth0stays untouched. What the same looks like permanently on real NICs is shown in Drill 8 in netplan, for reading only.
┌──── br-lab (bridge, VLAN-aware later) ─────┐
│ p-a p-b p-c p-t (Trunk) │
└──┬─────────┬─────────┬─────────┬───────────┘
┌──┴──┐ ┌──┴──┐ ┌──┴──┐ ┌──┴────────────┐
│ a │ │ b │ │ c │ │ t: eth0.10 │
│ .1 │ │ .2 │ │ .3 │ │ eth0.20 │
└─────┘ └─────┘ └─────┘ └───────────────┘
10.20.0.0/24 VLAN 10: a, b · VLAN 20: c
Drill 1: A Switch with Three Machines
Create the bridge, three namespaces with one veth pair each, the host end becomes a port of the bridge:
# on netz
sudo ip link add br-lab type bridge
sudo ip netns add a
sudo ip netns add b
sudo ip netns add c
sudo ip link add p-a type veth peer name eth0 netns a
sudo ip link add p-b type veth peer name eth0 netns b
sudo ip link add p-c type veth peer name eth0 netns c
sudo ip link set p-a master br-lab
sudo ip link set p-b master br-lab
sudo ip link set p-c master br-lab
sudo ip link set p-a up
sudo ip link set p-b up
sudo ip link set p-c up
sudo ip -n a link set eth0 up
sudo ip -n b link set eth0 up
sudo ip -n c link set eth0 up
sudo ip -n a link set lo up
sudo ip -n b link set lo up
sudo ip -n c link set lo up
sudo ip -n a addr add 10.20.0.1/24 dev eth0
sudo ip -n b addr add 10.20.0.2/24 dev eth0
sudo ip -n c addr add 10.20.0.3/24 dev eth0
bridge link
sudo ip netns exec a ping -c1 -W1 10.20.0.2 | tail -2Expected:
16: p-a@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br-lab state disabled priority 32 cost 2
17: p-b@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br-lab state disabled priority 32 cost 2
18: p-c@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br-lab state disabled priority 32 cost 2
1 packets transmitted, 0 received, 100% packet loss, time 0ms
The ports are up but stuck in state disabled. The bridge
itself is still down, and a switch that is switched off forwards
nothing:
# on netz
sudo ip link set br-lab up
bridge link
sudo ip netns exec a ping -c1 -W1 10.20.0.2 | tail -2Expected:
16: p-a@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br-lab state forwarding priority 32 cost 2
17: p-b@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br-lab state forwarding priority 32 cost 2
18: p-c@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br-lab state forwarding priority 32 cost 2
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 964.415/964.415/964.415/0.000 ms
Tried it: The first successful ping took almost a second. The failed attempt before it had left behind an ARP request whose timeout was still running. Only afterwards did
aask again, this time with a reply. With real switches you know this as “the first ping gets lost”.
Save your progress? Sign up for free
Drill 2: What the Bridge Learns
Each namespace has its own MAC on its eth0:
# on netz
sudo ip -n a -br link show eth0 | awk '{print $3}'
sudo ip -n b -br link show eth0 | awk '{print $3}'
sudo ip -n c -br link show eth0 | awk '{print $3}'
bridge fdb show br br-lab | grep -v permanentExpected:
06:76:da:1d:5c:11
d6:2b:48:df:34:b2
3a:69:87:bd:f0:c2
06:76:da:1d:5c:11 dev p-a master br-lab
d6:2b:48:df:34:b2 dev p-b master br-lab
3a:69:87:bd:f0:c2 dev p-c master br-lab
The bridge has already learned all three: each namespace sent a few
packets when it came up (IPv6 neighbor discovery), and the bridge
remembers for every frame on which port the sender MAC
came in. -s shows how long ago that was:
# on netz
bridge -s fdb show br br-lab | grep -v permanent
ip -d link show br-lab | grep -o 'ageing_time [0-9]*'Expected:
06:76:da:1d:5c:11 dev p-a used 0/0 master br-lab
d6:2b:48:df:34:b2 dev p-b used 1/1 master br-lab
3a:69:87:bd:f0:c2 dev p-c used 0/0 master br-lab
ageing_time 30000
used 1/1 means: used and refreshed one second ago. After
ageing_time (in hundredths of a second, i.e. 300 s) without
traffic, the bridge forgets an entry.
Where does a frame go whose destination the bridge does not know, or
a broadcast? To all ports except the one it came from:
flooding. Listen in b while a asks for the MAC
of c:
# on netz
sudo ip netns exec b timeout 3 tcpdump -eni eth0 -c2 arp &
sleep 0.5; sudo ip -n a neigh flush all; sudo ip netns exec a ping -c1 -W1 10.20.0.3 >/dev/null; waitExpected:
19:33:55.459946 06:76:da:1d:5c:11 > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Request who-has 10.20.0.3 tell 10.20.0.1, length 28
1 packet captured
b sees the ARP request (destination
ff:ff:ff:ff:ff:ff), even though it is not meant for
b. The actual ping from a to c is
no longer visible to b: the bridge forwards it straight to
p-c. Try it with icmp instead of
arp as the filter: 0 packets captured.
Save your progress? Sign up for free
Drill 3: Spanning Tree, Briefly
Two bridges, cabled twice, and a broadcast circles forever: STP prevents that. It blocks redundant paths. On the Linux bridge it is off:
# on netz
ip -d link show br-lab | grep -o 'stp_state [0-9]\|forward_delay [0-9]*'Expected:
forward_delay 1500
stp_state 0
Switching it on and reconnecting a port shows the price:
# on netz
sudo ip link set br-lab type bridge stp_state 1
sudo ip link set p-c down
sudo ip link set p-c up
sleep 1; bridge link show dev p-c
sleep 15; bridge link show dev p-c
sleep 16; bridge link show dev p-c
sudo ip link set br-lab type bridge stp_state 0Expected:
18: p-c@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br-lab state listening priority 32 cost 2
18: p-c@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br-lab state learning priority 32 cost 2
18: p-c@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br-lab state forwarding priority 32 cost 2
15 seconds each (forward_delay 1500) in
listening and learning, only then does the
port forward. A server booting via DHCP has already given up within that
half minute. That is why STP is usually off on bridges for VMs and
containers, and on real switches server ports have “PortFast” (or “edge
port”).
Save your progress? Sign up for free
Drill 4: VLAN Interfaces
First VLANs without a bridge: two namespaces, cabled directly, and on
each end a VLAN interface with ID 10. Both cable ends should be called
eth0 in their namespace.
Tried it:
sudo ip link add eth0 netns v1 type veth peer name eth0 netns v2fails withRTNETLINK answers: File exists. The pair is first created in the root namespace, andeth0already exists there. Withip -n v1it is created directly inv1:
# on netz
sudo ip netns add v1
sudo ip netns add v2
sudo ip -n v1 link add eth0 type veth peer name eth0 netns v2
sudo ip -n v1 link set eth0 up
sudo ip -n v2 link set eth0 up
sudo ip -n v1 link set lo up
sudo ip -n v2 link set lo up
sudo ip -n v1 link add link eth0 name eth0.10 type vlan id 10
sudo ip -n v2 link add link eth0 name eth0.10 type vlan id 10
sudo ip -n v1 addr add 10.30.10.1/24 dev eth0.10
sudo ip -n v2 addr add 10.30.10.2/24 dev eth0.10
sudo ip -n v1 link set eth0.10 up
sudo ip -n v2 link set eth0.10 up
sudo ip -n v1 -br a
sudo ip -n v1 -d link show eth0.10 | grep -o 'vlan protocol [^ ]* id [0-9]*'Expected:
lo UNKNOWN 127.0.0.1/8 ::1/128
eth0@if2 UP fe80::4048:a6ff:fecb:9b1/64
eth0.10@eth0 UP 10.30.10.1/24 fe80::4048:a6ff:fecb:9b1/64
vlan protocol 802.1Q id 10
eth0 itself has no IPv4 address; it sits on
eth0.10. On the wire, i.e. on eth0, you see
the tag with -e (Ethernet header):
# on netz
sudo ip netns exec v2 timeout 3 tcpdump -eni eth0 -c2 icmp &
sleep 0.5; sudo ip netns exec v1 ping -c1 -W1 10.30.10.2 | tail -2; waitExpected:
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.236/0.236/0.236/0.000 ms
19:35:13.048060 42:48:a6:cb:09:b1 > 2e:11:5f:b7:03:ca, ethertype 802.1Q (0x8100), length 102: vlan 10, p 0, ethertype IPv4 (0x0800), 10.30.10.1 > 10.30.10.2: ICMP echo request, id 4133, seq 1, length 64
19:35:13.048120 2e:11:5f:b7:03:ca > 42:48:a6:cb:09:b1, ethertype 802.1Q (0x8100), length 102: vlan 10, p 0, ethertype IPv4 (0x0800), 10.30.10.2 > 10.30.10.1: ICMP echo reply, id 4133, seq 1, length 64
ethertype 802.1Q (0x8100) … vlan 10: four bytes of tag
sit between the MAC addresses and the actual type, hence
length 102 instead of 98. And what if the other side
expects a different VLAN?
# on netz
sudo ip -n v2 link del eth0.10
sudo ip -n v2 link add link eth0 name eth0.20 type vlan id 20
sudo ip -n v2 addr add 10.30.10.2/24 dev eth0.20
sudo ip -n v2 link set eth0.20 up
sudo ip netns exec v1 ping -c1 -W1 10.30.10.2 | tail -2
sudo ip netns exec v2 timeout 3 tcpdump -eni eth0 -c2 &
sleep 0.5; sudo ip netns exec v1 ping -c1 -W1 10.30.10.2 >/dev/null; waitExpected:
1 packets transmitted, 0 received, 100% packet loss, time 0ms
19:35:15.323416 42:48:a6:cb:09:b1 > 2e:11:5f:b7:03:ca, ethertype 802.1Q (0x8100), length 102: vlan 10, p 0, ethertype IPv4 (0x0800), 10.30.10.1 > 10.30.10.2: ICMP echo request, id 4152, seq 1, length 64
19:35:15.344421 2e:11:5f:b7:03:ca > 33:33:00:00:00:16, ethertype 802.1Q (0x8100), length 94: vlan 20, p 0, ethertype IPv6 (0x86dd), fe80::2c11:5fff:feb7:3ca > ff02::16: HBH ICMP6, multicast listener report v2, 1 group record(s), length 28
The ping arrives with vlan 10, v2 now only
listens on VLAN 20 and drops it. Same addresses, same cable, no contact:
that is the separation VLANs are used for.
Save your progress? Sign up for free
Drill 5: The VLAN-Aware Bridge
Back to br-lab. Every port starts out in VLAN 1, even
though VLANs are not filtered at all yet:
# on netz
bridge vlan showExpected:
port vlan-id
br-lab 1 PVID Egress Untagged
p-a 1 PVID Egress Untagged
p-b 1 PVID Egress Untagged
p-c 1 PVID Egress Untagged
a and b should go into VLAN 10,
c into VLAN 20. The namespaces themselves notice nothing;
they keep sending untagged: their ports become access
ports.
# on netz
sudo ip link set br-lab type bridge vlan_filtering 1
sudo bridge vlan del dev p-a vid 1
sudo bridge vlan del dev p-b vid 1
sudo bridge vlan del dev p-c vid 1
sudo bridge vlan add dev p-a vid 10 pvid untagged
sudo bridge vlan add dev p-b vid 10 pvid untagged
sudo bridge vlan add dev p-c vid 20 pvid untagged
bridge vlan showExpected:
port vlan-id
br-lab 1 PVID Egress Untagged
p-a 10 PVID Egress Untagged
p-b 10 PVID Egress Untagged
p-c 20 PVID Egress Untagged
| Term | Meaning |
|---|---|
PVID |
Frames arriving untagged belong to this VLAN |
Egress Untagged |
The tag is removed when leaving through this port |
| neither | The port accepts and sends this VLAN only tagged (trunk) |
# on netz
sudo ip netns exec a ping -c1 -W1 10.20.0.2 | grep -o '[0-9] received'
sudo ip netns exec a ping -c1 -W1 10.20.0.3 | grep -o '[0-9] received'Expected:
1 received
0 received
a and c are in the same IP network and on
the same bridge, but can no longer reach each other.
Save your progress? Sign up for free
Drill 6: A Trunk
A fourth namespace t should be in both VLANs. It gets a
port that carries VLAN 10 and 20 tagged, and two VLAN
interfaces inside. This is how routers, firewalls and hypervisors attach
to switches:
# on netz
sudo ip netns add t
sudo ip link add p-t type veth peer name eth0 netns t
sudo ip link set p-t master br-lab
sudo ip link set p-t up
sudo bridge vlan del dev p-t vid 1
sudo bridge vlan add dev p-t vid 10
sudo bridge vlan add dev p-t vid 20
bridge vlan show dev p-t
sudo ip -n t link set eth0 up
sudo ip -n t link add link eth0 name eth0.10 type vlan id 10
sudo ip -n t link add link eth0 name eth0.20 type vlan id 20
sudo ip -n t addr add 10.20.0.10/24 dev eth0.10
sudo ip -n t addr add 10.20.0.20/24 dev eth0.20
sudo ip -n t link set eth0.10 up
sudo ip -n t link set eth0.20 up
sudo ip netns exec t ping -c1 -W1 -I eth0.10 10.20.0.1 | grep -o '[0-9] received'
sudo ip netns exec t ping -c1 -W1 -I eth0.20 10.20.0.3 | grep -o '[0-9] received'Expected:
port vlan-id
p-t 10
20
1 received
1 received
Because both VLANs use the same IP network here, -I
tells ping which interface to use. In real networks, each VLAN has its
own network. The difference between trunk and access port, captured
twice:
# on netz
sudo timeout 3 tcpdump -eni p-t -c2 icmp &
sleep 0.5; sudo ip netns exec t ping -c1 -W1 -I eth0.20 10.20.0.3 >/dev/null; wait
sudo timeout 3 tcpdump -eni p-c -c2 icmp &
sleep 0.5; sudo ip netns exec t ping -c1 -W1 -I eth0.20 10.20.0.3 >/dev/null; wait
bridge fdb show br br-lab | grep -v permanent | grep vlanExpected:
19:35:29.998939 86:b8:24:0d:28:5f > 3a:69:87:bd:f0:c2, ethertype 802.1Q (0x8100), length 102: vlan 20, p 0, ethertype IPv4 (0x0800), 10.20.0.20 > 10.20.0.3: ICMP echo request, id 4290, seq 1, length 64
19:35:29.999053 3a:69:87:bd:f0:c2 > 86:b8:24:0d:28:5f, ethertype 802.1Q (0x8100), length 102: vlan 20, p 0, ethertype IPv4 (0x0800), 10.20.0.3 > 10.20.0.20: ICMP echo reply, id 4290, seq 1, length 64
19:35:31.089141 86:b8:24:0d:28:5f > 3a:69:87:bd:f0:c2, ethertype IPv4 (0x0800), length 98: 10.20.0.20 > 10.20.0.3: ICMP echo request, id 4296, seq 1, length 64
19:35:31.089183 3a:69:87:bd:f0:c2 > 86:b8:24:0d:28:5f, ethertype IPv4 (0x0800), length 98: 10.20.0.3 > 10.20.0.20: ICMP echo reply, id 4296, seq 1, length 64
06:76:da:1d:5c:11 dev p-a vlan 10 master br-lab
d6:2b:48:df:34:b2 dev p-b vlan 10 master br-lab
3a:69:87:bd:f0:c2 dev p-c vlan 20 master br-lab
86:b8:24:0d:28:5f dev p-t vlan 20 master br-lab
86:b8:24:0d:28:5f dev p-t vlan 10 master br-lab
With a tag on the trunk port, without one on c’s access
port: the bridge adds and removes the tags. And it learns MAC addresses
per VLAN. t appears twice in the FDB with the same MAC.
Save your progress? Sign up for free
Drill 7: A Bond That Survives a Failure
A server srv with two links to a switch
(br-bond, on which the host has .1). The
bonding module has been loaded at boot since Day 0:
# on netz
sudo ip link add br-bond type bridge
sudo ip link set br-bond up
sudo ip addr add 10.50.0.1/24 dev br-bond
sudo ip netns add srv
sudo ip link add hb1 type veth peer name e1 netns srv
sudo ip link add hb2 type veth peer name e2 netns srv
sudo ip link set hb1 master br-bond
sudo ip link set hb2 master br-bond
sudo ip link set hb1 up
sudo ip link set hb2 up
sudo ip -n srv link add bond0 type bond mode active-backup miimon 100
sudo ip -n srv link set e1 master bond0
sudo ip -n srv link set e2 master bond0
sudo ip -n srv link set bond0 up
sudo ip -n srv link set lo up
sudo ip -n srv addr add 10.50.0.2/24 dev bond0
sudo ip -n srv -br linkExpected:
lo UNKNOWN 00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP>
e1@if21 UP 92:63:c6:fc:c5:6e <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP>
e2@if22 UP 92:63:c6:fc:c5:6e <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP>
bond0 UP 92:63:c6:fc:c5:6e <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP>
All three carry the same MAC: the bond takes over that of the first
slave, so that after a switchover the switch only has to learn a new
port, not a new address. /proc reveals the state, per
namespace:
# on netz
sudo ip netns exec srv cat /proc/net/bonding/bond0Expected (shortened):
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: e1
MII Status: up
MII Polling Interval (ms): 100
Slave Interface: e1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 92:63:c6:fc:c5:6e
Slave Interface: e2
MII Status: up
Link Failure Count: 0
Permanent HW addr: 8e:7b:d6:c8:d0:90
Now the failure: srv pings ten times per second for five
seconds, and after two seconds you pull the cable of e1
(the host end hb1):
# on netz
sudo ip netns exec srv ping -i 0.1 -c 50 -W1 10.50.0.1 > /tmp/fo.txt 2>&1 &
sleep 2; sudo ip link set hb1 down; wait
tail -2 /tmp/fo.txt
sudo ip netns exec srv grep -E "Currently Active|Slave Interface|MII Status|Link Failure" /proc/net/bonding/bond0
bridge fdb show br br-bond | grep 92:63Expected:
50 packets transmitted, 50 received, 0% packet loss, time 5099ms
rtt min/avg/max/mdev = 0.064/0.115/0.316/0.035 ms
Currently Active Slave: e2
MII Status: up
Slave Interface: e1
MII Status: down
Link Failure Count: 1
Slave Interface: e2
MII Status: up
Link Failure Count: 0
92:63:c6:fc:c5:6e dev hb2 master br-bond
Not a single ping lost. miimon 100 checks the link every
100 ms, e2 takes over, and the switch has already learned
the MAC on hb2.
# on netz
sudo ip link set hb1 up
sleep 1
sudo ip netns exec srv grep "Currently Active" /proc/net/bonding/bond0
sudo ip -n srv link set bond0 type bond primary e1
sudo ip netns exec srv grep -E "Primary Slave|Currently Active" /proc/net/bonding/bond0Expected:
Currently Active Slave: e2
Primary Slave: e1 (primary_reselect always)
Currently Active Slave: e1
Without primary, the bond stays on e2 after
the repair, because every switchover costs a brief jolt. With
primary e1 it returns to e1 as soon as the
link is up.
active-backup needs nothing from the switch. If you want
to use both links at the same time, take 802.3ad (LACP):
then the switch has to play along and combine the ports into one
channel. That does not work with a Linux bridge as the other end, so it
stays at a mention here.
Save your progress? Sign up for free
Drill 8: The Same in netplan, Read Only
On a real server, bond, VLAN and bridge live in netplan. A typical
setup: two NICs as a bond, VLAN 10 on top, a bridge for VMs on top of
that. So that nothing touches the real configuration, you let netplan
render into a separate directory (--root-dir):
# on netz
mkdir -p ~/np/etc/netplan
cat > ~/np/etc/netplan/70-beispiel.yaml <<'EOF'
network:
version: 2
ethernets:
ens19: {}
ens20: {}
bonds:
bond0:
interfaces: [ens19, ens20]
parameters:
mode: active-backup
mii-monitor-interval: 100
primary: ens19
vlans:
bond0.10:
id: 10
link: bond0
bridges:
br10:
interfaces: [bond0.10]
addresses: [10.60.10.5/24]
parameters:
stp: false
EOF
chmod 600 ~/np/etc/netplan/70-beispiel.yaml
netplan generate --root-dir ~/np; echo "rc=$?"
ls ~/np/run/systemd/network/
cat ~/np/run/systemd/network/10-netplan-bond0.netdev ~/np/run/systemd/network/10-netplan-ens19.networkExpected:
Failed to send reload request: Permission denied
Reload daemon failed: Interactive authentication required.
Command '['systemctl', 'daemon-reload', '--no-ask-password']' returned non-zero exit status 1.
rc=0
10-netplan-bond0.10.netdev
10-netplan-bond0.10.network
10-netplan-bond0.netdev
10-netplan-bond0.network
10-netplan-br10.netdev
10-netplan-br10.network
10-netplan-ens19.network
10-netplan-ens20.network
[NetDev]
Name=bond0
Kind=bond
[Bond]
Mode=active-backup
MIIMonitorSec=100ms
[Match]
Name=ens19
[Network]
LinkLocalAddressing=no
Bond=bond0
PrimarySlave=true
Tried it: Without
sudo,netplan generatestill renders, but then wants to reload systemd and fails at that. The return code stays 0, the files are there. That is exactly what we want: read, apply nothing.
The layering is the same as by hand: .netdev files
create virtual devices (bond, VLAN, bridge), .network files
wire them together (Bond=bond0) and assign addresses. By
the way, primary does not end up in the bond, but as
PrimarySlave=true on the NIC.
# on netz
rm -r ~/npSave your progress? Sign up for free
Exercise: Speed drills
- Which MAC addresses does
br-labknow in VLAN 20, and on which port? Target time: 20 s - Attach a namespace
dwith10.20.0.4/24as an access port in VLAN 20 tobr-laband prove that it reachescbut nota. Target time: 2 min - Which slave of
bond0is currently active? Just the name. Target time: 30 s
Solution
# on netz
bridge fdb show br br-lab vlan 20 | grep -v permanent
sudo ip netns add d
sudo ip link add p-d type veth peer name eth0 netns d
sudo ip link set p-d master br-lab
sudo bridge vlan del dev p-d vid 1
sudo bridge vlan add dev p-d vid 20 pvid untagged
sudo ip link set p-d up
sudo ip -n d link set eth0 up
sudo ip -n d addr add 10.20.0.4/24 dev eth0
sudo ip netns exec d ping -c1 -W1 10.20.0.3 | grep -o '[0-9] received'
sudo ip netns exec d ping -c1 -W1 10.20.0.1 | grep -o '[0-9] received'
sudo ip netns exec srv awk -F': ' '/Currently Active/{print $2}' /proc/net/bonding/bond0Expected:
3a:69:87:bd:f0:c2 dev p-c vlan 20 master br-lab stale
86:b8:24:0d:28:5f dev p-t vlan 20 master br-lab stale
1 received
0 received
e1
Save your progress? Sign up for free
Challenge
A colleague “just quickly reset the VLAN” on p-b:
# on netz
sudo bridge vlan del dev p-b vid 10
sudo bridge vlan add dev p-b vid 10
sudo ip -n a neigh flush all
sudo ip netns exec a ping -c2 -W1 10.20.0.2 | tail -2Expected:
2 packets transmitted, 0 received, 100% packet loss, time 1038ms
b is up, has its address, is attached to the bridge, and
VLAN 10 is set on its port as well. Find out what is missing and fix it
with one command.
Hint: Does b send tagged or untagged?
And what does the port do with untagged frames?
Solution
# on netz
bridge vlan show dev p-b
sudo ip -n a neigh show 10.20.0.2Expected:
port vlan-id
p-b 10
10.20.0.2 dev eth0 INCOMPLETE
VLAN 10 is set on p-b, but without
PVID Egress Untagged: the port is now a trunk for VLAN 10.
b sends untagged, and the port assigns untagged frames to
no VLAN, so the bridge drops them. a never gets an ARP
reply (INCOMPLETE).
# on netz
sudo bridge vlan add dev p-b vid 10 pvid untagged
bridge vlan show dev p-b
sudo ip netns exec a ping -c2 -W1 10.20.0.2 | tail -2Expected:
port vlan-id
p-b 10 PVID Egress Untagged
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.148/0.479/0.810/0.331 ms
The most common VLAN fault in everyday work: tagged versus untagged. One end speaks 802.1Q, the other does not, and there is no error message whatsoever.
Save your progress? Sign up for free
Checkpoint
After the challenge and speed drills:
# on netz
ip -d link show br-lab | grep -o 'vlan_filtering [0-9]'Expected: vlan_filtering 1
# on netz
sudo ip netns exec a ping -c1 -W1 10.20.0.2 | grep -o '[0-9] received'Expected: 1 received
# on netz
sudo ip netns exec a ping -c1 -W1 10.20.0.3 | grep -o '[0-9] received'Expected: 0 received
# on netz
sudo ip netns exec srv grep -c "MII Status: up" /proc/net/bonding/bond0Expected: 3 (the bond and both
slaves)
# on netz
ip netns list | wc -lExpected: 8 (a,
b, c, d, t,
v1, v2, srv)
Clean-up
# on netz
sudo ip netns del a
sudo ip netns del b
sudo ip netns del c
sudo ip netns del d
sudo ip netns del t
sudo ip netns del v1
sudo ip netns del v2
sudo ip netns del srv
sudo ip link del br-lab
sudo ip link del br-bond
rm -f /tmp/fo.txt
ip netns list | wc -l
ip -br linkExpected:
0
lo UNKNOWN 00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP>
eth0 UP bc:24:11:4d:d9:08 <BROADCAST,MULTICAST,UP,LOWER_UP>
Practice note
- First
bridge vlan show, then swap cables. If a device on a VLAN-aware bridge or on a switch reaches no one, it is in most cases tagged versus untagged or a wrong PVID.tcpdump -eon the port shows whether a tag comes along. - STP off on bridges for VMs. Hardly any booting guest tolerates 30 seconds of waiting per port. There you prevent loops with clean cabling, not with STP.
active-backupis the safe bond. It needs no switch configuration and survives a link failure without loss. LACP (802.3ad) brings more throughput, but only if both sides are configured identically. Andprimaryshould be set when one link is the better one.