您的位置:首页 > 运维架构 > Linux

centos&Linux 双网卡双网关的配置方法详解

2017-03-08 09:02 781 查看
最近公司需要在一台服务器上同时使用内网和外网,并且都需要跨网段访问,因此需要双网关,但是一台机子上只能有一个网关,那如何解决呢,这就需要在服务器上配置静态路由了,网上有很多这方面的文章但是讲的都不细致,对于我这种不是网络技术专业出身的人来说,需要自己一点点的摸索测试,现在将我的经验分享给大家,这个对于小白来说都是绝对有益的。

首先讲解下服务器网络初始状态:

1、局域网:192.168.0.0 网段的,需要配置的网关是192.168.1.206,子掩码:255.255.255.0

2、互联网:10.0.0.0 网段的,需要配置网关10.0.0.1   子掩码:255.255.255.0

第一步:

在服务器网卡上将内网配置好后,删除网关信息,不要有网关;

在外网网卡上将外网网络配置好,但是一定要配置好网关信息;

以上配置好后,会有这样的效果。能够ping通互联网地址,但是192.168其他的网段就ping不通了。

第二步:

添加静态路由信息

[root@home]# route -n

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

10.0.0.0            0.0.0.0         255.255.255.0    U          1       0        0     eth1

192.168.1.0       0.0.0.0       255.255.255.0    U           1       0        0     eth0

这里eth1是外网网卡,eth0是内网网卡。

[root@home]# route add -net 197.10.0.0 netmask 255.255.0.0 dev eth1

[root@home]# route add -net 197.10.0.0 netmask 255.255.0.0 gw 197.10.1.206

这样一来就将静态路由配置好了

[root@localhost network-scripts]# ping 192.168.7.205

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

64 bytes from 192.168.7.205: icmp_seq=1 ttl=254 time=2.77 ms

64 bytes from 192.168.7.205: icmp_seq=2 ttl=254 time=2.71 ms

64 bytes from 192.168.7.205: icmp_seq=3 ttl=254 time=2.72 ms

64 bytes from 192.168.7.205: icmp_seq=4 ttl=254 time=2.73 ms

64 bytes from 192.168.7.205: icmp_seq=5 ttl=254 time=2.68 ms

64 bytes from 192.168.7.205: icmp_seq=6 ttl=254 time=2.75 ms

[root@localhost network-scripts]# ping 202.108.22.5

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

64 bytes from 202.108.22.5: icmp_seq=1 ttl=53 time=23.8 ms

64 bytes from 202.108.22.5: icmp_seq=2 ttl=53 time=23.2 ms

64 bytes from 202.108.22.5: icmp_seq=3 ttl=53 time=23.5 ms

64 bytes from 202.108.22.5: icmp_seq=4 ttl=53 time=21.9 ms

64 bytes from 202.108.22.5: icmp_seq=5 ttl=53 time=23.8 ms

64 bytes from 202.108.22.5: icmp_seq=6 ttl=53 time=21.8 ms

64 bytes from 202.108.22.5: icmp_seq=7 ttl=53 time=21.5 ms
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: