vim /etc/iproute2/rt_tables 增加
252 cnc
251 tel
在 /etc/rc.local 里面增加
ip route flush table tel
ip route add default via 网关1 dev eth1 src IP1 table tel
ip rule add from IP1 table tel
ip route flush table cnc
ip route add default via 网关2 dev eth0 src IP2 table cnc
ip rule add from IP2 table cnc
注意红色部分即可
写成shell脚本如下
#!/bin/bash
ip1=”1.1.1.2″
e1=”eth0″
gw1=”1.1.1.1″
ip2=”2.2.2.2″
e2=”eth1″
gw2=”2.2.2.1″
#################################################
### 上面的配置要改改
### 下面就不要动了
#################################################
rt=”/etc/iproute2/rt_tables”
echo “252 cnc ” >> $rt
echo “251 tel ” >> $rt
rclocal=”/etc/rc.local”
echo “ip route flush table tel” >> $rclocal
echo “ip route add default via $gw1 dev $e1 src $ip1 table tel” >> $rclocal
echo “ip rule add from $ip1 table tel” >> $rclocal
echo “ip route flush table cnc” >> $rclocal
echo “ip route add default via $gw2 dev $e2 src $ip2 table cnc” >> $rclocal
echo “ip rule add from $ip2 table cnc” >> $rclocal
点此下载