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
首先讲解下服务器网络初始状态:
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
相关文章推荐
- VMware下CentOS6.4网卡设置为桥接模式静态IP配置方法详解
- ceph存储 Linux 网卡配置-centos&ubuntu
- 关于linux Centos 7一个网卡配置多个IP的方法
- centos配置网卡修改ip地址和修改网关的方法
- 关于linux Centos 7一个网卡配置多个IP的方法
- Linux系统网卡配置详解以及—常见问题的解决方法以及—硬盘移植后网卡的配置
- VMware下CentOS6.4网卡设置为桥接模式静态IP配置方法详解
- CentOS7网卡设置为桥接模式静态IP配置方法详解
- VMware下CentOS6.4网卡设置为桥接模式静态IP配置方法详解
- CentOS7网卡设置为桥接模式静态IP配置方法详解
- linux -- centos 下网卡配置文件ifcfg-eth*的选项说明
- Linux操作系统下IPTables配置方法详解
- linux下配置多网卡或多IP的方法
- Linux防火墙IPTables配置方法详解
- Linux下双网卡双网关路由表配置相关资料
- Linux操作系统下IPTables配置方法详解
- CentOS(Linux)下的apache服务器配置与管理方法分享
- Linux系统下一块网卡配置多个Ip地址方法
- Linux操作系统下IPTables配置方法详解【转】
- Linux操作系统下Iptables配置方法详解