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

转载于:https://www.cnblogs.com/music378/p/9267241.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值