Multiple Internet connections, multiple networks and split access in Linux

Posted by Swapneel Patnekar on Server Fault See other posts from Server Fault or by Swapneel Patnekar
Published on 2012-12-07T18:46:41Z Indexed on 2012/12/07 23:11 UTC
Read the original article Hit count: 396

I am having trouble setting up multiple internet connections for split access in Linux. We have 3 internet connections from 3 different ISP's. We want to configure our Linux gateway machine such that our three internal networks 10.2.1.0/24, 192.168.20.0/24 & 192.168.2.0/24 use ISP1, ISP2 and ISP3 respectively in a split access manner.

Outlined below is the layout/settings,

Interfaces of the Linux Gateway connected to Routers:

eth0: 10.1.1.2<---------->10.1.1.1(Internal Interface of ADSL Router)[ISP1]
eth1: 192.168.15.2<------>192.168.15.1(Internal Interface of 3G Router)[ISP2]
eth3: 192.168.1.2<------->192.168.1.1(Internal Interface of ADSL Router)[ISP3]

Kindly note that none of the interfaces in the Linux gateway has a public static IP address. Routers of ISP1 and ISP2 get assigned a dynamic public IP address when connected to the Internet, router of ISP3 has been assigned a public static IP address.

Interface of Linux gateway connected to a switch,

eth4:  10.2.1.1(LAN Interface for ISP1)
eth4:0 192.168.20.1(LAN interface for ISP2)
eth4:1 192.168.2.1(LAN Interface for ISP3)

eth4:0 & eth4:1 are virtual interfaces with eth4 being the interface connected physically.

Based on http://linux-ip.net/html/adv-multi-internet.html I've set the following routes,

ip route flush table 4
ip route show table main | grep -Ev ^default | while read ROUTE ; do ip route add table 4 $ROUTE done
ip route add table 4 default via 192.168.15.1
ip rule add fwmark 4 table 4
ip route flush cache

Additionally, using the following iptables rules to mark & route packets as per the guide mentioned above : http://pastebin.com/KzWHFGJA

At this point, computers from 192.168.2.0/24 network are successfully able to reach the Internet through ISP3. 192.168.20.0/24 and 10.2.1.0/24 are unable to access the Internet through ISP1 and ISP2 respectively.

Any inputs will be much appreciated !

© Server Fault or respective owner

Related posts about linux

Related posts about iptables