CentOS6.6 双网卡双网关配置

1.需求:
内网IP:10.63.215.7 网关:10.63.215.254
外网IP:180.168.29.92 网关:180.168.29.89
内外网均可以Ping通,可直接访问

2.IP配置:

[root@APPServer ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO=none
IPADDR=10.63.215.7
IPV6INIT="yes"
NETMASK="255.255.255.0"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="bc9e80f5-1b82-46ab-b39b-cc8ad2a81d16"
HWADDR=34:97:F6:5B:67:95

[root@APPServer ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE="eth1"
BOOTPROTO="dhcp"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="1b85cdd4-2a89-48f2-99fe-d2b7aa318954"
HWADDR=34:97:F6:5B:67:96

/etc/sysconfig/network中没写默认网关!

3.配置双网关:

[root@APPServer ~]# cat /etc/iproute2/rt_tables
#
# reserved values
#
255 local
254 main
253 default
0   unspec
#
# local
#
#1  inr.ruhep
252 e1
251 e0

接着敲命令:

ip route flush table e0
ip route add default via 10.63.215.254 dev eth0 src 10.63.215.7 table e0
ip route add 127.0.0.0/8 dev lo table e0
ip rule add from 10.63.215.7 table e0
ip route flush table e1
ip route add default via 180.168.29.89 dev eth1 src 180.168.29.92 table e1
ip route add 127.0.0.0/8 dev lo table e1
ip rule add from 180.168.29.92 table e1

敲完直接测试内外网是否全通,反正我这里是好了。

原理:把静态路由的命令加在 /etc/init.d/network。
但CentOS可能会自动还原这个文件,导致自己加的东西会消失,所以,还是加到开机启动脚本里面:

[root@APPServer ~]# cat /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 route flush table e0
ip route add default via 10.63.215.254 dev eth0 src 10.63.215.7 table e0
ip route add 127.0.0.0/8 dev lo table e0
ip rule add from 10.63.215.7 table e0
ip route flush table e1
ip route add default via 180.168.29.89 dev eth1 src 180.168.29.92 table e1
ip route add 127.0.0.0/8 dev lo table e1
ip rule add from 180.168.29.92 table e1

猜你喜欢

转载自www.cnblogs.com/music378/p/9267241.html