Dual Gateway

最後更新: 2015-08-10

個案

OS

  • eth0 x.x.x.x
  • eth1 y.y.y.y

x.x.x.x 及 y.y.y.y 可在同一 subnet

當有 c1 及 c2 分別訪問 x.x.x.x 及 y.y.y.y 時

那 c2 會沒有回應

原因

* By default, administrators can define a single, default route

=> if you receive traffic on eth1, the return traffic will go out eth0

解決方法

Adding a Second Routing Table

 


Adding a Second Routing Table

 

# 假設 "eth1" IP 是 192.168.88.184, GW 是 192.168.88.5

cat /etc/sysconfig/network-scripts/ifcfg-eth1

# The secondary network interface
DEVICE=eth1
BOOTPROTO=none
TYPE="Ethernet"
IPADDR=192.168.88.184
NETMASK=255.255.255.0

Step1: New Routing Table

cat /etc/iproute2/rt_tables

# reserved values
255     local
254     main
253     default
0       unspec

# add this row
1 rt2

Step2: Add route to New Routing Table

ip route add 192.168.88.0/24 dev eth1 src 192.168.88.184 table rt2

ip route add default via 192.168.88.5 dev eth1 table rt2

# 現在 System 係有兩個 routing table 的, 兩者河水不犯田水

checking

ip route list table rt2

192.168.88.0/24 dev eth1 scope link src 192.168.88.184
default via 192.168.88.5 dev eth1

Step3: Add Routing Rules

# So that the system knows when to use our new routing table

ip rule add from 192.168.88.184/32 table rt2

ip rule add to 192.168.88.184/32 table rt2

checking

ip rule show

0:      from all lookup local
32764:  from all to 192.168.88.184 lookup rt2
32765:  from 192.168.88.184 lookup rt2
32766:  from all lookup main
32767:  from all lookup default

Step4: Final testing on outside network

telnet x.x.x.x:7777

telnet y.y.y.y:7777

 


Making the Configuration permanent

 

 

 

 

Creative Commons license icon Creative Commons license icon