大佬教程收集整理的这篇文章主要介绍了CentOS6.6 双网卡双网关配置,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
1.需求:
内网IP:10.63.215.7 网关:10.63.215.254
外网IP:180.168.29.92 网关:180.168.29.89
内外网均可以Ping通,可直接访问
2.IP配置:
[[email protected] ~]# 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 [[email protected] ~]# 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.配置双网关:
[[email protected] ~]# 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可能会自动还原这个文件,导致自己加的东西会消失,所以,还是加到开机启动脚本里面:
[[email protected] ~]# 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
以上是大佬教程为你收集整理的CentOS6.6 双网卡双网关配置全部内容,希望文章能够帮你解决CentOS6.6 双网卡双网关配置所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。