Multi route
Problématique
Ce que j'appéle le multihoming / multi route est le fait qu'une machine appartienne à plusieurs réseaux et qu'elle ait des gateway par default sur plusieurs d'entre eux. L'idée c'est que les packets qui partent de l'interface if1 doivent sortir par la gateway définie pour cette interface et que les packets qui partent de l'interface if2 doivent eux sortir par la gateway définie pour celle-ci.
Explication
Pour ce faire, Linux nous fourni l'outil iproute2. Pour l'utiliser, cela consiste à créer des tables de routage différentes pour chaque interface et d'utiliser la bonne table au bon moment. Donc, tout d'abord on définit nos diffèrentes tables dans un fichier de lookup (à la /etc/hosts), il permet d'associer un nom à un numéro de table. On ne peut avoir que de 0 à 255 tables dont un certain nombre sont prédéfinies :
Mise en pratique
- Fichier /etc/network/interface :
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
up ethtool -s eth0 duplex full speed 100 autoneg off
auto eth0.401
iface eth0.401 inet static
address 217.174.193.129
netmask 255.255.255.240
up ip route add default via 217.174.193.142 table vl401
up ip rule add from 217.174.193.129 table vl401
auto eth0.402
iface eth0.402 inet static
address 217.174.194.129
netmask 255.255.255.240
up ip route add default via 217.174.194.142 table vl402
up ip rule add from 217.174.194.129 table vl402
auto eth0.403
iface eth0.403 inet static
address 217.174.195.129
netmask 255.255.255.240
up ip route add default via 217.174.195.142 table vl403
up ip rule add from 217.174.195.129 table vl403
auto eth0.404
iface eth0.404 inet static
address 217.174.202.145
netmask 255.255.255.240
gateway 217.174.202.158
auto eth0.7
iface eth0.7 inet static
address 217.174.210.80
netmask 255.255.255.192
up ip route add default via 217.174.210.126 table vl7
up ip rule add from 217.174.210.80 table vl7
- #cat /etc/iproute2/rt_tables
201 vl7 202 vl401 203 vl402 204 vl403 205 vl404
- # ip route
217.174.195.128/28 dev eth0.403 proto kernel scope link src 217.174.195.129 217.174.194.128/28 dev eth0.402 proto kernel scope link src 217.174.194.129 217.174.193.128/28 dev eth0.401 proto kernel scope link src 217.174.193.129 217.174.202.144/28 dev eth0.404 proto kernel scope link src 217.174.202.145 217.174.210.64/26 dev eth0.7 proto kernel scope link src 217.174.210.80 default via 217.174.202.158 dev eth0.404
- # ip rule
0: from all lookup local 32760: from 217.174.195.129 lookup vl403 32761: from 217.174.194.129 lookup vl402 32762: from 217.174.193.129 lookup vl401 32763: from 217.174.193.129 lookup vl401 32764: from 217.174.210.81 lookup vl7 32765: from 217.174.210.80 lookup vl7 32766: from all lookup main 32767: from all lookup default
- # netstat -rn
Table de routage IP du noyau Destination Passerelle Genmask Indic MSS Fenêtre irtt Iface 217.174.195.128 0.0.0.0 255.255.255.240 U 0 0 0 eth0.403 217.174.194.128 0.0.0.0 255.255.255.240 U 0 0 0 eth0.402 217.174.193.128 0.0.0.0 255.255.255.240 U 0 0 0 eth0.401 217.174.202.144 0.0.0.0 255.255.255.240 U 0 0 0 eth0.404 217.174.210.64 0.0.0.0 255.255.255.192 U 0 0 0 eth0.7 0.0.0.0 217.174.202.158 0.0.0.0 UG 0 0 0 eth0.404