比如我們的LINUX有3個網卡 eth0: 192.168.1.1 (區域網路) eth1: 172.17.1.2 (default gw=172.17.1.1,可以上INTERNET) eth2: 192.168.10.2 (連接第二路由192.168.10.1,也可以上INTERNET) 實現兩個目的 1、讓192.168.1.66從第二路由上網,其他人走預設路由 2、讓所有人訪問192.168.1.1的FTP時,轉到192.168.10.96上 配置方法: vi /etc/iproute2/rt_tables # # reserved values # 255 local 254 main 253 default 100 ROUTE2 # ip route default via 172.17.1.1 dev eth1 # ip route default via 192.168.10.1 dev eth2 table ROUTE2 # ip rule add from 192.168.1.66 pref 1001 table ROUTE2 # ip rule add to 192.168.10.96 pref 1002 table ROUTE2 # echo 1 >; /proc/sys/net/ipv4/ip_forward # iptables -t nat -A POSTROUTING -j MASQUERADE # iptables -t nat -A PREROUTING -d 192.168.1.1 -p tcp --dport 21 -j DNAT --to 192.168.10.96 # ip route flush cache
http://phorum.study-area.org/viewtopic.php?t=10085 引用:# 對外網卡 EXT_IF="eth0" # HiNet IP EXT_IP1="111.111.111.111" EXT_MASK1="24" GW1="111.111.111.1" # SeedNet IP EXT_IP2="222.222.222.222" EXT_MASK2="24" GW2="222.222.222.1" # ?#93;定 ip ip addr add $EXT_IP1/$EXT_MASK1 dev $EXT_IF ip addr add $EXT_IP2/$EXT_MASK2 dev $EXT_IF # ?#93;定 HiNet routing ip rule add to $EXT_IP1/$EXT_MASK1 lookup 201 ip route add default via $GW1 dev $EXT_IF table 201 # ?#93;定 SeedNet routing ip rule add to $EXT_IP2/$EXT_MASK2 lookup 202 ip route add default via $GW2 dev $EXT_IF table 202 # ?#93;定 Default route ip route replace default equalize \ nexthop via $GW1 dev $EXT_IF \ nexthop via $GW2 dev $EXT_IF # 清除 route cache ip route flush cache 它這裡的ip rule也是這麼使用的