Dual connection to Internet with help of iproute
August 2, 2005
Usually when you configure your linux box to connect to a network you enter one single default gateway. That means that all all packages sent from your box to an unknown network is sent to this single gateway. But when you have multiple Internet connection to a single machine it won't work, you have to send the responce from the same ip-address that the request was retreived on.
So, enough of introduction, iproute solves all of this. And thats nice :)
This is how I did...
I have the machine directly connected to internet with ip 81.232.135.141. And then a local network with ip 192.168.1.14 and a gateway on that network with ip 192.168.1.1 acting as a router to Internet on an other line.
ip rule add from 81.232.135.141 lookup 1
ip route add 0/0 via 81.232.135.1 table 1
ip rule add from 192.168.1.14 lookup 2
ip route add 192.168.1.0/24 via 192.168.1.14 table 2
ip route add 0/0 via 192.168.1.1 table 2
This will make an own lookup routing table for each network interface and send the responce to the correct router. Also note that I don't specify any default gateway here. The default gateway will be uses when something from this machine tries to make a connection to any unknown ip. But since it is added with help of DHCP when I get the ip 81.232.135.141 I won't have to add it again.
Maybe this might help someone...
So, enough of introduction, iproute solves all of this. And thats nice :)
This is how I did...
I have the machine directly connected to internet with ip 81.232.135.141. And then a local network with ip 192.168.1.14 and a gateway on that network with ip 192.168.1.1 acting as a router to Internet on an other line.
ip rule add from 81.232.135.141 lookup 1
ip route add 0/0 via 81.232.135.1 table 1
ip rule add from 192.168.1.14 lookup 2
ip route add 192.168.1.0/24 via 192.168.1.14 table 2
ip route add 0/0 via 192.168.1.1 table 2
This will make an own lookup routing table for each network interface and send the responce to the correct router. Also note that I don't specify any default gateway here. The default gateway will be uses when something from this machine tries to make a connection to any unknown ip. But since it is added with help of DHCP when I get the ip 81.232.135.141 I won't have to add it again.
Maybe this might help someone...