Network
Source based routing
Tested on Debian 12
If your host have more than one NIC (in different nets), you maybe want to specify which traffic goes to which NIC.
One use-case is, that you have a docker host, which should be accessible via NIC-1 (primary net) and the docker service should be accessible via another NIC-2 (secondary net).
Therfore you have to create routing information for the traffic coming from the docker service.
(Ref:
1,
2,
3,
4)
-
Create a new table for the secondary net:
sudo nano /etc/iproute2/rt_tables
add at the end of this file:
Note: 200
must be a positive int and dmz
can be any name you want
200 dmz
-
Create if-up script to make the routing information persistent (create routing information at every boot)
sudo nano /etc/network/if-up.d/docker_services_dmz
With the following content:
Note: enp6s19
is the NIC-2, 172.18.0.0/16
the docker service net and 10.0.0.1
the gateway from secondary net
#!/bin/sh
if [ "$IFACE" = "enp6s19" ]; then
ip rule add from 172.18.0.0/16 table dmz
ip route add default via 10.0.0.1 dev enp6s19 table dmz
fi
Make this script executable:
sudo chmod +x /etc/network/if-up.d/docker_services_dmz
-
Reboot or restart networking.service
with sudo systemctl restart networking.service