centos7下配置ip forward的方法-mile米乐体育

这篇文章将为大家详细讲解有关centos7下配置ip forward的方法,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

linux 中ip forward功能是一个比较方便实用的功能,只需要简单配置,添加几条路由,即可实现ip转发。本文基于centos 7下采取一台机器充当虚拟路由,来实现windows环境与linux环境中相互通信。具体见下文,供大家参考。

一、环境及需求说明

本地测试环境,由于win7 vmware这台机器网卡太新,无法被vmware exsi识别,无奈之下就直接装了个win7,然后再上面基于vmware workstation 12开启了一些临时测试的虚拟机。其次本地直连网段192.168.1.0 ip有限,而又希望直接从本机(如图win10) ssh连接到这些虚拟机,因此考虑使用linux的ip转发功能来实现。

上述图片中已经列出了各个节点的ip信息,红色的虚拟机充当软路由,配置好之后,实现win10 直接ssh到虚拟机。

二、虚拟路由服务器配置

###查看网卡信息 [root@centos7-router~]#ipaddr 1:lo:mtu65536qdiscnoqueuestateunknown link/loopback00:00:00:00:00:00brd00:00:00:00:00:00 inet127.0.0.1/8scopehostlo valid_lftforeverpreferred_lftforever inet6::1/128scopehost valid_lftforeverpreferred_lftforever 2:eno16777728:mtu1500qdiscpfifo_faststateupqlen1000 link/ether00:0c:29:9c:eb:2dbrdff:ff:ff:ff:ff:ff inet172.24.8.254/24brd172.24.8.255scopeglobaleno16777728 valid_lftforeverpreferred_lftforever inet6fe80::20c:29ff:fe9c:eb2d/64scopelink valid_lftforeverpreferred_lftforever 3:eno33554960:mtu1500qdiscpfifo_faststateupqlen1000 link/ether00:0c:29:9c:eb:37brdff:ff:ff:ff:ff:ff inet192.168.1.175/24brd192.168.1.255scopeglobaldynamiceno33554960 valid_lft82384secpreferred_lft82384sec inet6fe80::20c:29ff:fe9c:eb37/64scopelink valid_lftforeverpreferred_lftforever  ###查看路由表 [root@centos7-router~]#route-n kerneliproutingtable###缺省情况下,每块网卡都有一个基于本网段的路由记录 destinationgatewaygenmaskflagsmetricrefuseiface 0.0.0.0192.168.1.10.0.0.0ug10000eno33554960 172.24.8.00.0.0.0255.255.255.0u10000eno16777728 192.168.1.00.0.0.0255.255.255.0u10000eno33554960  ###使用ip命令方式查看路由 [root@centos7-router~]#iproutelist defaultvia192.168.1.1deveno33554960protostaticmetric100 172.24.8.0/24deveno16777728protokernelscopelinksrc172.24.8.254metric100 192.168.1.0/24deveno33554960protokernelscopelinksrc192.168.1.175metric100  ###开启ipforward [root@centos7-router~]#cp/usr/lib/sysctl.d/50-default.conf/usr/lib/sysctl.d/50-default.conf.bk [root@centos7-router~]#echo"net.ipv4.ip_forward=1">>/usr/lib/sysctl.d/50-default.conf [root@centos7-router~]#grepip_forward/usr/lib/sysctl.d/50-default.conf net.ipv4.ip_forward=1 [root@centos7-router~]#sysctl-p###如不生效重启一下os

三、centos7-a主机下添加路由

###查看当前主机ip信息 [root@centos7-a~]#ipaddrlist 1:lo:mtu65536qdiscnoqueuestateunknown link/loopback00:00:00:00:00:00brd00:00:00:00:00:00 inet127.0.0.1/8scopehostlo valid_lftforeverpreferred_lftforever inet6::1/128scopehost valid_lftforeverpreferred_lftforever 2:eno16777728:mtu1500qdiscpfifo_faststateupqlen1000 link/ether00:0c:29:57:26:9dbrdff:ff:ff:ff:ff:ff inet172.24.8.131/24brd172.24.8.255scopeglobaldynamiceno16777728 valid_lft1088secpreferred_lft1088sec inet6fe80::20c:29ff:fe57:269d/64scopelink valid_lftforeverpreferred_lftforever  ###查看当前主机路由信息 [root@centos7-a~]#iproutelist 172.24.8.0/24deveno16777728protokernelscopelinksrc172.24.8.131metric100  [root@centos7-a~]##author:leshami [root@centos7-a~]##blog:http://blog.csdn.net/leshami [root@centos7-a~]#iprouteadddefaultvia172.24.8.254 [root@centos7-a~]#iproutelist defaultvia172.24.8.254deveno16777728 172.24.8.0/24deveno16777728protokernelscopelinksrc172.24.8.131metric100  ###测试到虚拟路由器网关ip连通性 [root@centos7-a~]#ping172.24.8.254-c2 ping172.24.8.254(172.24.8.254)56(84)bytesofdata. 64bytesfrom172.24.8.254:icmp_seq=1ttl=64time=0.268ms 64bytesfrom172.24.8.254:icmp_seq=2ttl=64time=0.302ms  ---172.24.8.254pingstatistics--- 2packetstransmitted,2received,0%packetloss,time1000ms rttmin/avg/max/mdev=0.268/0.285/0.302/0.017ms  ###测试到虚拟路由器ip连通性 [root@centos7-a~]#ping192.168.1.175-c2 ping192.168.1.175(192.168.1.175)56(84)bytesofdata. 64bytesfrom192.168.1.175:icmp_seq=1ttl=64time=0.475ms 64bytesfrom192.168.1.175:icmp_seq=2ttl=64time=0.443ms  ---192.168.1.175pingstatistics--- 2packetstransmitted,2received,0%packetloss,time1000ms rttmin/avg/max/mdev=0.443/0.459/0.475/0.016ms

四、windows 10下配置路由

###当前环境 c:\>systeminfo|findstrbuild osversion:10.0.14393n/abuild14393 osbuildtype:multiprocessorfree  ###查看当前的路由信息 c:\>routeprint-4 =========================================================================== interfacelist 7...54ab3axxb8ea......intel(r)ethernetconnectioni219-v 21...ac2b6e5f3b57......microsoftwi-fidirectvirtualadapter ...... =========================================================================== ipv4routetable =========================================================================== activeroutes: networkdestinationnetmaskgatewayinterfacemetric 0.0.0.00.0.0.0192.168.1.1192.168.1.24235 127.0.0.0255.0.0.0on-link127.0.0.1331 127.0.0.1255.255.255.255on-link127.0.0.1331 127.255.255.255255.255.255.255on-link127.0.0.1331 172.24.10.0255.255.255.0on-link172.24.10.1291 172.24.10.1255.255.255.255on-link172.24.10.1291 172.24.10.255255.255.255.255on-link172.24.10.1291 192.168.1.0255.255.255.0on-link192.168.1.242291 192.168.1.242255.255.255.255on-link192.168.1.242291 192.168.1.255255.255.255.255on-link192.168.1.242291 192.168.16.0255.255.255.0on-link192.168.16.1291 192.168.16.1255.255.255.255on-link192.168.16.1291 192.168.16.255255.255.255.255on-link192.168.16.1291 224.0.0.0240.0.0.0on-link127.0.0.1331 224.0.0.0240.0.0.0on-link192.168.1.242291 224.0.0.0240.0.0.0on-link192.168.16.1291 224.0.0.0240.0.0.0on-link172.24.10.1291 255.255.255.255255.255.255.255on-link127.0.0.1331 255.255.255.255255.255.255.255on-link192.168.1.242291 255.255.255.255255.255.255.255on-link192.168.16.1291 255.255.255.255255.255.255.255on-link172.24.10.1291 =========================================================================== persistentroutes: none  ###添加持久化路由 c:\>routeadd172.24.8.0mask255.255.255.0192.168.1.175-p ok!  c:\>routeprint-4  ipv4routetable =========================================================================== activeroutes: networkdestinationnetmaskgatewayinterfacemetric 0.0.0.00.0.0.0192.168.1.1192.168.1.24235 127.0.0.0255.0.0.0on-link127.0.0.1331 127.0.0.1255.255.255.255on-link127.0.0.1331 127.255.255.255255.255.255.255on-link127.0.0.1331 172.24.8.0255.255.255.0192.168.1.175192.168.1.24236 172.24.10.0255.255.255.0on-link172.24.10.1291 172.24.10.1255.255.255.255on-link172.24.10.1291 172.24.10.255255.255.255.255on-link172.24.10.1291 192.168.1.0255.255.255.0on-link192.168.1.242291 192.168.1.242255.255.255.255on-link192.168.1.242291 192.168.1.255255.255.255.255on-link192.168.1.242291 192.168.16.0255.255.255.0on-link192.168.16.1291 192.168.16.1255.255.255.255on-link192.168.16.1291 192.168.16.255255.255.255.255on-link192.168.16.1291 224.0.0.0240.0.0.0on-link127.0.0.1331 224.0.0.0240.0.0.0on-link192.168.1.242291 224.0.0.0240.0.0.0on-link192.168.16.1291 224.0.0.0240.0.0.0on-link172.24.10.1291 255.255.255.255255.255.255.255on-link127.0.0.1331 255.255.255.255255.255.255.255on-link192.168.1.242291 255.255.255.255255.255.255.255on-link192.168.16.1291 255.255.255.255255.255.255.255on-link172.24.10.1291 =========================================================================== persistentroutes:###以下为添加的持久化路由记录 networkaddressnetmaskgatewayaddressmetric 172.24.8.0255.255.255.0192.168.1.1751 ===========================================================================

五、验证两边连通性

###从linux端pingwindows10 [root@centos7-a~]#ping192.168.1.242-c2 ping192.168.1.242(192.168.1.242)56(84)bytesofdata. 64bytesfrom192.168.1.242:icmp_seq=1ttl=63time=1.70ms 64bytesfrom192.168.1.242:icmp_seq=2ttl=63time=1.10ms  ---192.168.1.242pingstatistics--- 2packetstransmitted,2received,0%packetloss,time1002ms rttmin/avg/max/mdev=1.101/1.404/1.707/0.303ms  ###从windows10端pinglinux c:\>ping172.24.8.131-t  pinging172.24.8.131with32bytesofdata: replyfrom172.24.8.131:bytes=32time=1msttl=63 replyfrom172.24.8.131:bytes=32time=1msttl=63

注,如果测试有问题,请考虑是否被防火墙拦住。

关于“centos7下配置ip forward的方法”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

展开全文
内容来源于互联网和用户投稿,文章中一旦含有米乐app官网登录的联系方式务必识别真假,本站仅做信息展示不承担任何相关责任,如有侵权或涉及法律问题请联系米乐app官网登录删除

最新文章

网站地图