Let’s say you have a linux machine with two ethernet adapters inside it, connected to 2 ISPs. In this case you will need to add the gateway for both ISPs to your routing tables.
In this example we will use the following subnets for the two ISPs:
We set up the first ISP as usual, GW in /etc/sysconfig/network and IP address + netmask… in /etc/sysconfig/network-scripts/ifcfg-eth0
For the second GW we add one custom table in /etc/iproute2/rt_tables, which should look like this:
[root@server ~]# cat /etc/iproute2/rt_tables # # reserved values # 255 local 254 main 253 default 0 unspec # # local # #1 inr.ruhep 200 my_custom_table
In our case the above custom table my_custom_table is created.
After this we need to add our secondary ISP subnet to that table:
ip rule add from 192.168.10.0/24 lookup my_custom_table
Last we need to add the default GW for the secondary IP address:
ip route add default via 192.168.10.1 dev eth1 table my_custom_table
With the above setup you should be able to setup two GWs on your system for two different ISPs.
The GW of the first ISP will still take precedence over the second one, however this can be overridden by either changing the number preceding the my_custom_table in /etc/iproute2/rt_tables or by adding different networks to that table to set them to be routed through it.
If you need to reach some IP address or subnet through the secondary interface you should just add:
ip rule add from IP.IP.IP.IP/MASK lookup my_custom_table