首页 > 开发 > 其他 > 正文

添加路由让多网卡网关工作正常

2018-10-16 21:24:01
字体:
来源:转载
供稿:网友

常规状态下一台服务器的两个网卡,是只能配置一个网关的,如果两个网卡都配置网关的话 ,那么很抱歉,这时网络是会出现故障的,肯定至少有一个网卡的地址是不管用的。

上一次去托管机房给客户安装服务器,一个网卡需要配置一个公网地址,需要配置网关,另一个需要和机房客户的另一台服务器通讯,但是需要安装这台服务器和客户原先的那台服务器不在一个机架上,机房分配的地址和原先的服务器又不在同一个网段。

网络需求:

需要安装的服务器:

eth0:addr:211.X.X.50 eth1(也就是机房分配的地址):

mask:255.255.255.252 addr:10.0.3.5 mask:255.255.255.0

geteway:211.X.X.49 gateway:10.0.3.253

原先的服务器:

addr:10.0.1.6

mask:255.255.255.0

给eth0设置过IP、网关之后是可以上公网的,这个是肯定的,除非网络有问题;但是给eth1设置过IP之后是不能和原先的服务器(10.0.1.6)通讯的。

[root@testServer etc]# ping 10.0.1.6

PING 10.0.1.6 (10.0.1.6) 56(84) bytes of data.

From 10.0.3.253 icmp_seq=1 Destination Net Unreachable

From 10.0.3.253 icmp_seq=2 Destination Net Unreachable

From 10.0.3.253 icmp_seq=3 Destination Net Unreachable

From 10.0.3.253 icmp_seq=4 Destination Net Unreachable

这个时候需要添加一个路由,让10.0.1.0网段和10.0.3.0网段互相识别。

[root@testServer etc]# route add -net 10.0.0.0/8 gw 10.0.3.253 eth1

[root@testServer etc]# route

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

10.0.3.252 * 255.255.255.252 U 0 0 0 eth1

211.X.X.48 * 255.255.255.252 U 0 0 0 eth0

169.254.0.0 * 255.255.0.0 U 0 0 0 eth1

10.0.0.0 10.0.3.253 255.0.0.0 UG 0 0 0 eth1

default 211.X.X..49 0.0.0.0 UG 0 0 0 eth0

添加过这个路由之后再ping:

[root@testServer etc]# ping 10.0.1.6

PING 10.0.1.1 (10.0.1.1) 56(84) bytes of data.

64 bytes from 10.0.1.1: icmp_seq=1 ttl=255 time=3.11 ms

64 bytes from 10.0.1.1: icmp_seq=2 ttl=255 time=1.01 ms

64 bytes from 10.0.1.1: icmp_seq=3 ttl=255 time=0.808 ms

64 bytes from 10.0.1.1: icmp_seq=4 ttl=255 time=1.05 ms

64 bytes from 10.0.1.1: icmp_seq=5 ttl=255 time=0.902 ms

这个时候是可以通讯的,但是这还没有完,因为这个时候只要一重启机器,刚才添加的那个路由就会消失,两天机器还是不能够通讯。但是这个该怎么办呢?不用着急,有办法,把刚才添加路由的那条命令再添加到这个文件/etc/rc.local的最后一行,然后保存退出。这样就ok了,重启机器也不怕了。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表