Posted by: kezhong | April 1, 2012

Setup Multiple Routes on Fedora 16

Our one server had two network interface cards(NICs) , and they used two different subnets. We wanted to use one NIC for our VIP customers, and the other NIC for normal customers. But when we configured network, we could not implement it.

I searched the solution, found Configuring Multiple Default Routes in Linux, followed the steps, and worked.

For the security reason, I don’t use public IPs here. I assume that
eth0 192.168.1.5 netmask 255.255.255.0
eth1 172.16.2.5 netmask 255.255.255.0
eth0’s gateway: 192.168.1.1
eth1’s gateway: 172.16.2.1

Before setup multiple routes, when I set 192.168.1.1 as default gateway, I could only ping 192.168.1.5 from outside, and could not ping 172.16.2.5. When I set 172.16.2.1 as default gateway, I could only ping 172.16.2.5 from outside, and could not ping 192.168.1.5.

Step 1:  Create new policy routing table entries
# echo “1 s192” >> /etc/iproute2/rt_tables
# echo “2 s172” >> /etc/iproute2/rt_tables

Step 2: Create rc.local script and enable it
# vi /etc/rc.d/rc.local
#!/bin/bash
/sbin/ip route add 192.168.1.0/24 dev eth0 src 192.168.1.5 table s192
/sbin/ip route add default via 192.168.1.1 dev eth0 table s192
/sbin/ip rule add from 192.168.1.0/24 table s192
/sbin/ip rule add to 192.168.1.0/24 table s192
/sbin/ip route add 172.16.2.0/24 dev eth1 src 172.16.2.5 table s172
/sbin/ip route add default via 172.16.2.1 dev eth1 table s172
/sbin/ip rule add from 172.16.2.0/24 table s172
/sbin/ip rule add to 172.16.2.0/24 table s172

# chmod u+x /etc/rc.d/rc.local
# systemctl enable rc-local.service

Step 3:  Reboot and verify
# ip rule show
0: from all lookup local
32762: from all to 172.16.2.0/24 lookup s172
32763: from 172.16.2.0/24 lookup s172
32764: from all to 192.168.1.0/24 lookup s192
32765: from 192.168.1.0/24 lookup s192
32766: from all lookup main
32767: from all lookup default

After setup, I could ping both 192.168.1.5 and 172.16.2.5 from outside.


Responses

  1. checkout http://www.ispunity.com, its an opensource project which can automatically multipath on lan and wan.

  2. nice article, thnx bro ;)


Leave a comment

Categories