Linux下双网卡双ip-双外网网关-电信联通双线主机设置

1、实现:通过运营商提供的智能DNS,把电信用户访问时,数据进电信的网卡,出来时也从电信的网关出来,访问联通时,从联通网卡时,联通网卡出。这样速度就会快,实现双线主机的功能。

2、网卡信息:
电信IP(TEL):114.80.0.4 netmask 255.255.255.128 gateway 114.80.0.3
联通IP(CNC):112.65.0.2 netmask 255.255.255.0 gateway 112.65.0.1

3、vi /etc/iproute2/rt_tables,增加网通和电信两个路由表
251 tel   电信路由表
252 cnc   网通路由表

4、设置电信的路由表
ip route flush table tel    #清空路由表
ip route add default via 114.80.0.3 dev eth0 src 114.80.0.4 table tel 
ip rule add from 114.80.0.4 table tel

5、设置联通的路由表
ip route flush table cnc 
ip route add default via 112.65.0.1 dev eth1 src 112.65.0.2 table cnc 
ip rule add from 112.65.0.2 table cnc

6、配置network启动脚本文件 在结尾exit 0之前增加如下内容:
# vi /etc/rc.d/init.d/network

ip route flush table tel 
ip route add default via 114.80.0.3 dev eth0 src 114.80.0.4 table tel 
ip rule add from 114.80.0.4 table tel

ip route flush table cnc 
ip route add default via 112.65.0.1 dev eth1 src 112.65.0.2 table cnc 
ip rule add from 112.65.0.2 table cnc

exit 0

7、重启系统或网络可能失效,请加入启动脚本:
如果是ubuntu/debian,系统启动脚本是/etc/rc.local 
如果是RedHat/centos,系统启动脚本是/etc/rc.d/rc.local

如果是ubuntu/debian,网络启动脚本是/etc/init.d/networking 
如果是RedHat/centos,网络启动脚本是/etc/rc.d/init.d/network

猜你喜欢

转载自www.cnblogs.com/Crazy-Liu/p/12761299.html
今日推荐