linux 双网卡双网关配置

linux admin 5922℃ 0评论

有这种需求的客户一般是国内和国外都有业务,需要用到国内和国际线路。 这里以 centos 6.5 配置为例!

说明:两个网卡都配置好 IP 信息,只有走默认网关的一条线路是通的,所以要用到策略路由来配置另一条线路的路由
1.ip rule add from 172.163.1.66 table 100 (添加 100 的路由表,用于此国内线路 IP)
ip rule add from 192.168.1.66 table 101 (添加 101 的路由表,用于此国外线路 IP)

然后用 ip rule show 查看策略路由,是否添加成功

2.策略路由添加好后,为两条线路指定网关

ip route add default via 172.163.1.1 table 100 (国内线路 IP 网关为172.163.1.1)
ip route add default via 192.168.1.1 table 101 (国外线路 IP 网关为172.163.1.1)
这样两条线路的路由已设置好,都能通了。没问题后把这 4 段命令写到
/etc/rc.local 文件里边,系统启动就会自动执行。如果没写到这个文件里边系统重启后会失效,再次启动后要重新以上操作

[root@oralcedb ~]# vi /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.

# You can put your own initialization stuff in here if you don’t

# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
ip rule add from 172.163.1.66 table 100
ip rule add from 192.168.1.66 table 101
ip route add default via 172.163.1.1 table 100 ip route add default via 192.168.1.1 table 101

转载请注明:我的主页 » linux 双网卡双网关配置

喜欢 (1)or分享 (0)

您必须 登录 才能发表评论!