Day 4: Routing by Hand: Forwarding, Policy Routing, VRFs
Goal: Build a router out of a namespace, with two uplinks. Decide which traffic takes which uplink: by metric, by source, by mark. Routes that drop packets on purpose. And cleanly separate two customers with the same addresses, using VRFs · Duration: approx. 90 min · Prerequisite: Day 2
Briefing
- A Linux router decides per packet in two steps. First, the
rules (
ip rule) are checked in order and say which routing table to look in. Then the kernel searches that table for the most specific route. Without your own rules there are onlylocal,mainanddefault, and everything you have seen so far withip routewas inmain. - Policy routing means: additional tables and rules that decide not only by destination, but also by source, incoming interface or a mark.
- A VRF (Virtual Routing and Forwarding) is a separate routing world inside the same namespace: interfaces in a VRF see only its table. This lets two customers use the same addresses.
rp_filteris a plausibility check for incoming packets: would I reply along the same path? With asymmetric routing it is the most common silent packet eater.
┌────┐ 10.40.1.0/24 10.41.0.0/24 (ISP 1) ┌────────────────┐
│ c1 ├──────────────┐ ┌──────────┐ up1 ─────────────── isp1 │ inet │
└────┘ └───┤ eth1 │ │ 198.51.100.1 │
┌────┐ 10.40.2.0/24 ┌───┤ eth2 r │ up2 ─────────────── isp2 │ (the Internet) │
│ c2 ├──────────────┘ └──────────┘ 10.42.0.0/24 (ISP 2) └────────────────┘
└────┘
198.51.100.0/24 is a network reserved for documentation.
In the lab it plays “the internet” without affecting any real
destination.
Drill 1: The Router
Four namespaces, four cables. This time all pairs are created
directly in the router r (like the VLAN pairs on Day 3), so
the router ends get meaningful names:
# on netz
sudo ip netns add r
sudo ip netns add c1
sudo ip netns add c2
sudo ip netns add inet
sudo ip -n r link set lo up
sudo ip -n c1 link set lo up
sudo ip -n c2 link set lo up
sudo ip -n inet link set lo up
sudo ip -n r link add eth1 type veth peer name eth0 netns c1
sudo ip -n r link add eth2 type veth peer name eth0 netns c2
sudo ip -n r link add up1 type veth peer name isp1 netns inet
sudo ip -n r link add up2 type veth peer name isp2 netns inet
sudo ip -n r addr add 10.40.1.1/24 dev eth1
sudo ip -n r addr add 10.40.2.1/24 dev eth2
sudo ip -n r addr add 10.41.0.2/24 dev up1
sudo ip -n r addr add 10.42.0.2/24 dev up2
sudo ip -n c1 addr add 10.40.1.10/24 dev eth0
sudo ip -n c2 addr add 10.40.2.20/24 dev eth0
sudo ip -n inet addr add 10.41.0.1/24 dev isp1
sudo ip -n inet addr add 10.42.0.1/24 dev isp2
sudo ip -n inet addr add 198.51.100.1/32 dev lo
sudo ip -n r link set eth1 up
sudo ip -n r link set eth2 up
sudo ip -n r link set up1 up
sudo ip -n r link set up2 up
sudo ip -n c1 link set eth0 up
sudo ip -n c2 link set eth0 up
sudo ip -n inet link set isp1 up
sudo ip -n inet link set isp2 up
sudo ip -n c1 route add default via 10.40.1.1
sudo ip -n c2 route add default via 10.40.2.1
sudo ip -n inet route add 10.40.1.0/24 via 10.41.0.2
sudo ip -n inet route add 10.40.2.0/24 via 10.42.0.2
sudo ip -n r -br aExpected:
lo UNKNOWN 127.0.0.1/8 ::1/128
eth1@if2 UP 10.40.1.1/24 fe80::bc12:5bff:fea9:613f/64
eth2@if2 UP 10.40.2.1/24 fe80::c5f:acff:fe13:513e/64
up1@if2 UP 10.41.0.2/24 fe80::d424:68ff:fec8:4b92/64
up2@if3 UP 10.42.0.2/24 fe80::c872:83ff:feaf:5352/64
inet gets routes back into both customer networks, each
via the matching ISP. That is the return path on which the ping from
rechts failed on Day 2. Now forwarding in
r:
# on netz
sudo ip netns exec r sysctl net.ipv4.ip_forward net.ipv4.conf.all.rp_filter net.ipv4.conf.default.rp_filter
sudo ip netns exec c1 ping -c1 -W1 10.40.2.20 | grep -o '[0-9] received'
sudo ip netns exec r sysctl -w net.ipv4.ip_forward=1
sudo ip netns exec c1 ping -c1 -W1 10.40.2.20 | grep -o '[0-9] received'Expected:
net.ipv4.ip_forward = 0
net.ipv4.conf.all.rp_filter = 2
net.ipv4.conf.default.rp_filter = 2
0 received
net.ipv4.ip_forward = 1
1 received
Tried it:
ip_forwardstarts at 0 in every new namespace, butrp_filterstarts at 2, as on the host. The kernel takes over some settings from the root namespace and not others. So in a new namespace, always check what applies instead of assuming it.
Save your progress? Sign up for free
Drill 2: Two Uplinks, One Metric
Two default routes in r. The one with the lower metric
wins; the other is the backup:
# on netz
sudo ip -n r route add default via 10.41.0.1 metric 100
sudo ip -n r route add default via 10.42.0.1 metric 200
sudo ip -n r route show default
sudo ip netns exec r ip route get 198.51.100.1
sudo ip netns exec c1 tracepath -n 198.51.100.1Expected:
default via 10.41.0.1 dev up1 metric 100
default via 10.42.0.1 dev up2 metric 200
198.51.100.1 via 10.41.0.1 dev up1 src 10.41.0.2 uid 0
cache
1?: [LOCALHOST] pmtu 1500
1: 10.40.1.1 0.245ms
1: 10.40.1.1 0.028ms
2: 198.51.100.1 0.183ms reached
Now ISP 1 fails. The other end goes away, and the link to
r loses carrier:
# on netz
sudo ip -n inet link set isp1 down
sudo ip -n r route show default
sudo ip netns exec r ip route get 198.51.100.1
sudo ip netns exec c1 ping -c1 -W1 198.51.100.1 | grep -o '[0-9] received'Expected:
default via 10.41.0.1 dev up1 metric 100 linkdown
default via 10.42.0.1 dev up2 metric 200
198.51.100.1 via 10.41.0.1 dev up1 src 10.41.0.2 uid 0
cache
0 received
Tried it: The route via
up1is markedlinkdown, but is still used. The backup does not step in. Linux only discards routes over a link without carrier if you explicitly ask for it:
# on netz
sudo ip netns exec r sysctl net.ipv4.conf.all.ignore_routes_with_linkdown
sudo ip netns exec r sysctl -w net.ipv4.conf.all.ignore_routes_with_linkdown=1
sudo ip netns exec r ip route get 198.51.100.1
sudo ip netns exec c1 ping -c1 -W1 198.51.100.1 | grep -o '[0-9] received'Expected:
net.ipv4.conf.all.ignore_routes_with_linkdown = 0
net.ipv4.conf.all.ignore_routes_with_linkdown = 1
198.51.100.1 via 10.42.0.1 dev up2 src 10.42.0.2 uid 0
cache
0 received
Now r takes the path via ISP 2, and the ping still
fails. The request arrives, with source 10.40.1.10. But
inet only knows the path via ISP 1 for
10.40.1.0/24, and that one is dead. In the real world it is
even simpler: ISP 2 does not know your network at all. A second uplink
therefore always needs NAT (Day 2) or your own addresses that both ISPs
route (BGP, Day 12).
ISP 1 comes back:
# on netz
sudo ip -n inet link set isp1 up
sleep 1
sudo ip netns exec r ip route get 198.51.100.1
sudo ip -n inet routeExpected:
198.51.100.1 via 10.41.0.1 dev up1 src 10.41.0.2 uid 0
cache
10.40.2.0/24 via 10.42.0.2 dev isp2
10.41.0.0/24 dev isp1 proto kernel scope link src 10.41.0.1
10.42.0.0/24 dev isp2 proto kernel scope link src 10.42.0.1
The route to 10.40.1.0/24 is missing in
inet. As on Day 1: whoever takes an interface down loses
all manually set routes over it, even after bringing it back up. So set
it again:
# on netz
sudo ip -n inet route add 10.40.1.0/24 via 10.41.0.2
sudo ip netns exec c1 ping -c1 -W1 198.51.100.1 | grep -o '[0-9] received'Expected: 1 received
Save your progress? Sign up for free
Drill 3: A Separate Table for ISP 2
Goal: c2 should always go via ISP 2, c1
still via ISP 1. Metrics cannot do that; they apply to everyone. It
takes a second table and a rule. Tables have numbers; a file gives them
names:
# on netz
grep -v '^#' /etc/iproute2/rt_tables
echo "200 isp2" | sudo tee /etc/iproute2/rt_tables.d/labor.conf
sudo ip -n r route add default via 10.42.0.1 table isp2
sudo ip -n r route show table isp2
sudo ip -n r route show table 200Expected:
255 local
254 main
253 default
0 unspec
200 isp2
default via 10.42.0.1 dev up2
default via 10.42.0.1 dev up2
The names file applies to the whole VM; the tables themselves belong
to the namespace. Now the rule: everything coming from
10.40.2.0/24 looks in isp2:
# on netz
sudo ip -n r rule add from 10.40.2.0/24 lookup isp2 priority 1000
sudo ip netns exec r ip ruleExpected:
0: from all lookup local
1000: from 10.40.2.0/24 lookup isp2
32766: from all lookup main
32767: from all lookup default
A plain ip route get no longer helps: it asks from the
router’s own point of view, without a source. With from and
iif you simulate a forwarded packet:
# on netz
sudo ip netns exec r ip route get 198.51.100.1 from 10.40.1.10 iif eth1
sudo ip netns exec r ip route get 198.51.100.1 from 10.40.2.20 iif eth2
sudo ip netns exec r ip route get 198.51.100.1Expected:
198.51.100.1 from 10.40.1.10 via 10.41.0.1 dev up1
cache iif eth1
198.51.100.1 from 10.40.2.20 via 10.42.0.1 dev up2 table isp2
cache iif eth2
198.51.100.1 via 10.41.0.1 dev up1 src 10.41.0.2 uid 0
cache
The proof at the other end, captured in inet:
# on netz
sudo ip netns exec inet timeout 3 tcpdump -ni isp2 -c2 icmp 2>&1 | grep IP &
sleep 0.5; sudo ip netns exec c2 ping -c1 -W1 198.51.100.1 | grep -o '[0-9] received'; wait
sudo ip netns exec inet timeout 3 tcpdump -ni isp1 -c1 icmp 2>&1 | grep IP &
sleep 0.5; sudo ip netns exec c1 ping -c1 -W1 198.51.100.1 | grep -o '[0-9] received'; waitExpected:
1 received
19:42:14.564707 IP 10.40.2.20 > 198.51.100.1: ICMP echo request, id 5314, seq 1, length 64
19:42:14.564862 IP 198.51.100.1 > 10.40.2.20: ICMP echo reply, id 5314, seq 1, length 64
1 received
19:42:15.686596 IP 10.40.1.10 > 198.51.100.1: ICMP echo request, id 5322, seq 1, length 64
Save your progress? Sign up for free
Drill 4: Order Matters
Rules are processed by priority, lowest number first, and the first
matching table with a route wins. A rule after main never
gets a turn as long as main has a default route:
# on netz
sudo ip -n r rule add from 10.40.1.0/24 lookup isp2 priority 40000
sudo ip netns exec r ip rule
sudo ip netns exec r ip route get 198.51.100.1 from 10.40.1.10 iif eth1Expected:
0: from all lookup local
1000: from 10.40.2.0/24 lookup isp2
32766: from all lookup main
32767: from all lookup default
40000: from 10.40.1.0/24 lookup isp2
198.51.100.1 from 10.40.1.10 via 10.41.0.1 dev up1
cache iif eth1
With a priority before main, it takes effect:
# on netz
sudo ip -n r rule del priority 40000
sudo ip -n r rule add from 10.40.1.0/24 lookup isp2 priority 1100
sudo ip netns exec r ip route get 198.51.100.1 from 10.40.1.10 iif eth1
sudo ip -n r rule del priority 1100Expected:
198.51.100.1 from 10.40.1.10 via 10.42.0.1 dev up2 table isp2
cache iif eth1
So whoever creates rules always sets the priority explicitly and leaves room between the numbers.
Save your progress? Sign up for free
Drill 5: Routing by Mark
Instead of by source, a rule can decide by a mark
(fwmark). Normally the firewall sets it, for example “everything to port
443 via ISP 2”. ping -m sets it directly:
# on netz
sudo ip -n r rule add fwmark 0x1 lookup isp2 priority 900
sudo ip netns exec r ip route get 198.51.100.1 mark 1
sudo ip netns exec inet timeout 3 tcpdump -ni isp2 -c1 icmp 2>&1 | grep IP &
sleep 0.5; sudo ip netns exec r ping -m 1 -c1 -W1 198.51.100.1 | grep -o '[0-9] received'; waitExpected:
198.51.100.1 via 10.42.0.1 dev up2 table isp2 src 10.42.0.2 mark 1 uid 0
cache
1 received
19:42:32.754932 IP 10.42.0.2 > 198.51.100.1: ICMP echo request, id 5439, seq 1, length 64
And if c1 sets the mark?
# on netz
sudo ip netns exec inet timeout 3 tcpdump -ni isp1 -c1 icmp 2>&1 | grep IP &
sleep 0.5; sudo ip netns exec c1 ping -m 1 -c1 -W1 198.51.100.1 | grep -o '[0-9] received'; waitExpected:
1 received
19:42:33.851517 IP 10.40.1.10 > 198.51.100.1: ICMP echo request, id 5447, seq 1, length 64
Tried it: The mark from
c1does not arrive inr; the packet goes via ISP 1. A veth pair between two namespaces clears the mark on the way across. So the router itself has to do the marking, with a firewall rule in its namespace (nftables course).
Save your progress? Sign up for free
Drill 6: Routes That Drop
Not every route leads somewhere. Three types drop on purpose, with different levels of politeness:
# on netz
sudo ip -n r route add blackhole 203.0.113.0/26
sudo ip -n r route add unreachable 203.0.113.64/26
sudo ip -n r route add prohibit 203.0.113.128/26
sudo ip netns exec c1 ping -c1 -W1 203.0.113.1 2>&1 | sed -n '2p;/transmitted/p'
sudo ip netns exec c1 ping -c1 -W1 203.0.113.65 2>&1 | sed -n '2p;/transmitted/p'
sudo ip netns exec c1 ping -c1 -W1 203.0.113.129 2>&1 | sed -n '2p;/transmitted/p'Expected:
1 packets transmitted, 0 received, 100% packet loss, time 0ms
From 10.40.1.1 icmp_seq=1 Destination Host Unreachable
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms
From 10.40.1.1 icmp_seq=1 Packet filtered
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms
| Route | What the sender notices | Use |
|---|---|---|
blackhole |
Nothing, the packet vanishes | Silently swallow attack traffic, avoid loops |
unreachable |
ICMP “Host Unreachable”, immediately | Network does not exist here, sender should give up quickly |
prohibit |
ICMP “Packet filtered” (administratively prohibited) | Network is blocked |
On the router itself, the errors look different:
# on netz
sudo ip netns exec r ping -c1 -W1 203.0.113.1 2>&1 | head -1
sudo ip netns exec r ping -c1 -W1 203.0.113.65 2>&1 | head -1
sudo ip netns exec r ping -c1 -W1 203.0.113.129 2>&1 | head -1Expected:
ping: connect: Invalid argument
ping: connect: No route to host
ping: Do you want to ping broadcast? Then -b. If not, check your local firewall rules
Tried it: With
prohibitthe kernel returns “permission denied”, andpinginterprets that as a broadcast attempt. The message is misleading: it is a route, not a broadcast.
Save your progress? Sign up for free
Drill 7: Two Customers, the Same Addresses
A provider router (pe) has two customers, and both use
10.99.0.0/24. Without VRFs this goes wrong, shown briefly
in throwaway namespaces:
# on netz
sudo ip netns add x
sudo ip netns add xb
sudo ip netns add xg
sudo ip -n x link add xb0 type veth peer name eth0 netns xb
sudo ip -n x link add xg0 type veth peer name eth0 netns xg
sudo ip -n x addr add 10.99.0.1/24 dev xb0
sudo ip -n x addr add 10.99.0.1/24 dev xg0
sudo ip -n x link set xb0 up
sudo ip -n x link set xg0 up
sudo ip -n xb addr add 10.99.0.2/24 dev eth0
sudo ip -n xb link set eth0 up
sudo ip -n xg addr add 10.99.0.2/24 dev eth0
sudo ip -n xg link set eth0 up
sudo ip -n x route
sudo ip netns exec x ip route get 10.99.0.2
sudo ip netns del x
sudo ip netns del xb
sudo ip netns del xgExpected:
10.99.0.0/24 dev xb0 proto kernel scope link src 10.99.0.1
10.99.0.0/24 dev xg0 proto kernel scope link src 10.99.0.1
10.99.0.2 dev xb0 src 10.99.0.1 uid 0
cache
Linux accepts the same address on two interfaces without complaint.
But main contains two identical routes, and the first one
always wins: the second customer is never reachable. Now with VRFs. The
vrf module has been loaded since Day 0:
# on netz
sudo ip netns add pe
sudo ip netns add kb
sudo ip netns add kg
sudo ip -n pe link set lo up
sudo ip -n kb link set lo up
sudo ip -n kg link set lo up
sudo ip -n pe link add vrf-blau type vrf table 10
sudo ip -n pe link add vrf-gruen type vrf table 20
sudo ip -n pe link set vrf-blau up
sudo ip -n pe link set vrf-gruen up
sudo ip -n pe link add kb0 type veth peer name eth0 netns kb
sudo ip -n pe link add kg0 type veth peer name eth0 netns kg
sudo ip -n pe link set kb0 master vrf-blau
sudo ip -n pe link set kg0 master vrf-gruen
sudo ip -n pe addr add 10.99.0.1/24 dev kb0
sudo ip -n pe addr add 10.99.0.1/24 dev kg0
sudo ip -n pe link set kb0 up
sudo ip -n pe link set kg0 up
sudo ip -n kb addr add 10.99.0.2/24 dev eth0
sudo ip -n kb link set eth0 up
sudo ip -n kg addr add 10.99.0.2/24 dev eth0
sudo ip -n kg link set eth0 up
sudo ip -n kb link set eth0 address 02:00:00:00:0b:02
sudo ip -n pe vrf show
sudo ip -n pe route show vrf vrf-blau
sudo ip -n pe route show table 20
sudo ip -n pe routeExpected:
Name Table
-----------------------
vrf-blau 10
vrf-gruen 20
10.99.0.0/24 dev kb0 proto kernel scope link src 10.99.0.1
10.99.0.0/24 dev kg0 proto kernel scope link src 10.99.0.1
local 10.99.0.1 dev kg0 proto kernel scope host src 10.99.0.1
broadcast 10.99.0.255 dev kg0 proto kernel scope link src 10.99.0.1
The fixed MAC for kb is just an identifying mark for
what follows. Each VRF has its own table; main is empty.
That is why a plain ping goes nowhere, and you have to say which
VRF:
# on netz
sudo ip netns exec pe ping -c1 -W1 10.99.0.2 2>&1 | head -1
sudo ip netns exec pe ip vrf exec vrf-blau ping -c1 -W1 10.99.0.2 | grep -o '[0-9] received'
sudo ip netns exec pe ping -I vrf-gruen -c1 -W1 10.99.0.2 | grep -o '[0-9] received'
sudo ip -n pe neigh show vrf vrf-blau
sudo ip -n pe neigh show vrf vrf-gruen
sudo ip netns exec pe ip ruleExpected:
ping: connect: Network is unreachable
1 received
ping: Warning: source address might be selected on device other than: vrf-gruen
1 received
10.99.0.2 dev kb0 lladdr 02:00:00:00:0b:02 REACHABLE
10.99.0.2 dev kg0 lladdr 56:87:4f:a2:3c:47 REACHABLE
0: from all lookup local
1000: from all lookup [l3mdev-table]
32766: from all lookup main
32767: from all lookup default
The same address 10.99.0.2, reached twice, with two
different MACs. ip vrf exec starts a program so that all
its sockets are bound to the VRF; ping -I binds only this
one socket. This is made possible by the l3mdev-table rule,
which is created automatically with the first VRF: it sends packets from
a VRF interface into that VRF’s table.
Save your progress? Sign up for free
Exercise: Speed drills
- Via which gateway does a packet from
c2to198.51.100.1leave the router? Just the address. Target time: 30 s - Show the contents of table
isp2. Target time: 10 s - Show only the routes of VRF
vrf-gruen. Target time: 15 s
Solution
# on netz
sudo ip netns exec r ip route get 198.51.100.1 from 10.40.2.20 iif eth2 | awk '{print $5}' | head -1
sudo ip -n r route show table isp2
sudo ip -n pe route show vrf vrf-gruenExpected:
10.42.0.1
default via 10.42.0.1 dev up2
10.99.0.0/24 dev kg0 proto kernel scope link src 10.99.0.1
Save your progress? Sign up for free
Challenge
Two changes at once, as in real life. ISP 1 now sends replies to
c2 via itself instead of via ISP 2 (asymmetric), and a
colleague has set rp_filter to strict for hardening:
# on netz
sudo ip -n inet route replace 10.40.2.0/24 via 10.41.0.2
sudo ip netns exec r sysctl -w net.ipv4.conf.all.rp_filter=1 net.ipv4.conf.up1.rp_filter=1
sudo ip netns exec c2 ping -c2 -W1 198.51.100.1 | grep -o '[0-9] received'Expected:
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.up1.rp_filter = 1
0 received
c2 no longer reaches the internet. Find out where the
replies end up, and bring c2 back online without reverting
the route in inet.
Hint: Do replies arrive at r? And on
which interface would r itself send toward
198.51.100.1 if the packet came from c2?
Solution
# on netz
sudo ip netns exec r timeout 3 tcpdump -ni up1 -c1 icmp 2>&1 | grep IP &
sleep 0.5; sudo ip netns exec c2 ping -c1 -W1 198.51.100.1 >/dev/null; wait
sudo ip netns exec r nstat -az TcpExtIPReversePathFilter
sudo ip netns exec r ip route get 198.51.100.1 from 10.40.2.20 iif eth2Expected:
19:43:07.157646 IP 198.51.100.1 > 10.40.2.20: ICMP echo reply, id 5672, seq 1, length 64
#kernel
TcpExtIPReversePathFilter 3 0.0
198.51.100.1 from 10.40.2.20 via 10.42.0.1 dev up2 table isp2
cache iif eth2
The reply arrives on up1. But the path from
r back to the sender would go via up2 (table
isp2). Strict rp_filter (1) requires both to
be the same interface, and drops the packet. The counter
TcpExtIPReversePathFilter counts every drop, for all
protocols despite Tcp in its name. Loose (2) only checks
whether there is any path back:
# on netz
sudo ip netns exec r sysctl -w net.ipv4.conf.up1.rp_filter=2 net.ipv4.conf.all.rp_filter=2
sudo ip netns exec c2 ping -c2 -W1 198.51.100.1 | grep -o '[0-9] received'Expected:
net.ipv4.conf.up1.rp_filter = 2
net.ipv4.conf.all.rp_filter = 2
2 received
Tried it: At first the challenge only had
conf.all.rp_filter=1, and everything kept working. Per interface, the kernel uses the higher value ofalland the interface itself, andup1was set to 2. If you want to hardenrp_filter, you have to set both values. If you want to loosen it, too.
Save your progress? Sign up for free
Checkpoint
After the challenge:
# on netz
sudo ip netns exec r ip rule | wc -lExpected: 5
# on netz
sudo ip netns exec r ip route get 198.51.100.1 from 10.40.2.20 iif eth2 | grep -o 'dev up[12]'Expected: dev up2
# on netz
sudo ip netns exec r ip route get 198.51.100.1 from 10.40.1.10 iif eth1 | grep -o 'dev up[12]'Expected: dev up1
# on netz
sudo ip netns exec c2 ping -c1 -W1 198.51.100.1 | grep -o '[0-9] received'Expected: 1 received
# on netz
sudo ip netns exec pe ip vrf exec vrf-gruen ping -c1 -W1 10.99.0.2 | grep -o '[0-9] received'Expected: 1 received
Clean-up
Rules, tables, VRFs and forwarding live in the namespaces and go away with them. Only the table name lives on the VM:
# on netz
sudo ip netns del r
sudo ip netns del c1
sudo ip netns del c2
sudo ip netns del inet
sudo ip netns del pe
sudo ip netns del kb
sudo ip netns del kg
sudo rm /etc/iproute2/rt_tables.d/labor.conf
ip netns list | wc -l
ip rule
sysctl -n net.ipv4.ip_forwardExpected:
0
0: from all lookup local
32766: from all lookup main
32767: from all lookup default
0
Practice note
ip route get … from … iif …before every change. With policy routing, a plainip route gettells you nothing anymore. Only with source and incoming interface do you see which rule and which table a forwarded packet really hits.- Two uplinks are two problems. The outbound path is
quickly built, the return path is not: without NAT or your own
addresses, no reply comes back via the second ISP. And
ignore_routes_with_linkdownshould be set, otherwise a dead link remains the best route. rp_filterand asymmetry do not get along. Strict mode is right on servers with one NIC, often wrong on routers with several paths. If replies vanish without a trace,nstat -az TcpExtIPReversePathFilteris the first place to look.- VRF instead of namespace when a router separates several worlds. Namespaces separate everything, including processes. VRFs separate only the routing; a routing daemon like FRR sees all VRFs and serves them together (Part B).
- This is the Linux routing everything else builds on. Part B lets FRR fill these tables instead of your hand, and on Day 15 the router namespace, two uplinks and NAT become a complete vRouter: a highly available gateway pair with BGP, VRRP and dnsmasq.