分类: 系统运维
2010-09-19 14:59:12
服务器环境:
网卡一(eth0)电信IP:114.80.66.145 网关地址:114.80.66.1
网卡二(eth1)网通IP:60.29.231.160 网关地址:60.29.231.1
可以使用Putty远程登录运行以下脚本即可:引用代码:
TEL="eth0"
TEL_IP="114.80.66.145"
TEL_GW="114.80.66.1"
CNC="eth1"
CNC_IP="60.29.231.160"
CNC_GW="60.29.231.1"
echo "252 TEL" >> /etc/iproute2/rt_tables
echo "251 CNC" >> /etc/iproute2/rt_tables
echo "ip route replace default via $TEL_GW dev $TEL" >> /etc/rc.d/rc.local
echo "ip route flush table TEL" >> /etc/rc.d/rc.local
echo "ip route add default via $TEL_GW dev $TEL src $TEL_IP table TEL" >> /etc/rc.d/rc.local
echo "ip rule add from $TEL_IP table TEL" >> /etc/rc.d/rc.local
echo "ip route flush table CNC" >> /etc/rc.d/rc.local
echo "ip route add default via $CNC_GW dev $CNC src $CNC_IP table CNC" >> /etc/rc.d/rc.local
echo "ip rule add from $CNC_IP table CNC" >> /etc/rc.d/rc.local
运行以上代码把设置加到启动项里,让系统开机时运行一次就可以了。即让从电信IP过来的请求按照电信路由返回,从网通IP过来的请求从网通路由返回。这样就搞定了,是不是很简单?
本文转自: