1.现象描述
VMware中装的ubuntu,host机是win7,VMware中用的NAT模式,Host机可以上网(用浏览器可以打开网页),ubuntu也能上网(同样也是通过浏览器可以看网页),并且host机和ubuntu之间可以相互Ping通,在win7下也能ping到外网,但是现在问题来了:在Ubuntu下不能ping到外网。
上面的操作过程为:1.查看win7的IP,结果如下:
C:\Users\Administrator>ipconfig Windows IP Configuration Ethernet adapter Local Area Connection: Connection-specific DNS Suffix . : Link-local IPv6 Address . . . . . : fe80::e9fe:1c1:5174:6585%11 IPv4 Address. . . . . . . . . . . : 192.168.1.25 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.1.1 Ethernet adapter VMware Network Adapter VMnet8: Connection-specific DNS Suffix . : Link-local IPv6 Address . . . . . : fe80::650a:ea63:6f6b:31fd%14 IPv4 Address. . . . . . . . . . . : 192.168.16.1 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . :
2.查看Ubuntu的IP,结果如下:
cy@cy:~$ ifconfig eth0 Link encap:以太网 硬件地址 00:0c:29:9d:3e:18 inet 地址:192.168.16.151 广播:192.168.16.255 掩码:255.255.255.0 inet6 地址: fe80::20c:29ff:fe9d:3e18/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 跃点数:1 接收数据包:5589 错误:0 丢弃:0 过载:0 帧数:0 发送数据包:6624 错误:0 丢弃:0 过载:0 载波:0 碰撞:0 发送队列长度:1000 接收字节:1015270 (1.0 MB) 发送字节:563164 (563.1 KB) 中断:19 基本地址:0x2024
3.确保win7可以ping到外网,结果如下:
C:\Users\Administrator>ping www.baidu.com Pinging www.a.shifen.com [115.239.210.27] with 32 bytes of data: Reply from 115.239.210.27: bytes=32 time=53ms TTL=55 Reply from 115.239.210.27: bytes=32 time=48ms TTL=55 Reply from 115.239.210.27: bytes=32 time=47ms TTL=55 Reply from 115.239.210.27: bytes=32 time=48ms TTL=55 Ping statistics for 115.239.210.27: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 47ms, Maximum = 53ms, Average = 49ms
4.从win7 到 Ubuntu的测试:
C:\Users\Administrator>ping 192.168.16.151 Pinging 192.168.16.151 with 32 bytes of data: Reply from 192.168.16.151: bytes=32 time<1ms TTL=64 Reply from 192.168.16.151: bytes=32 time<1ms TTL=64 Reply from 192.168.16.151: bytes=32 time<1ms TTL=64 Reply from 192.168.16.151: bytes=32 time<1ms TTL=64 Ping statistics for 192.168.16.151: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms
5.从 Ubuntu到win7的测试:
cy@cy:~$ ping 192.168.16.1 PING 192.168.16.1 (192.168.16.1) 56(84) bytes of data. 64 bytes from 192.168.16.1: icmp_req=1 ttl=64 time=1.16 ms 64 bytes from 192.168.16.1: icmp_req=2 ttl=64 time=0.469 ms 64 bytes from 192.168.16.1: icmp_req=3 ttl=64 time=0.495 ms ^C --- 192.168.16.1 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2005ms rtt min/avg/max/mdev = 0.469/0.711/1.169/0.324 ms cy@cy:~$ ping 192.168.1.25 PING 192.168.1.25 (192.168.1.25) 56(84) bytes of data. 64 bytes from 192.168.1.25: icmp_req=1 ttl=128 time=1.31 ms 64 bytes from 192.168.1.25: icmp_req=2 ttl=128 time=1.36 ms 64 bytes from 192.168.1.25: icmp_req=3 ttl=128 time=1.19 ms ^C --- 192.168.1.25 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2005ms rtt min/avg/max/mdev = 1.195/1.290/1.363/0.081 ms
6.结果,从Ubuntu不能ping 到外网去:
cy@cy:~$ ping www.baidu.com PING www.a.shifen.com (115.239.210.26) 56(84) bytes of data. ^C --- www.a.shifen.com ping statistics --- 23 packets transmitted, 0 received, 100% packet loss, time 22075ms
2.解决办法
这个问题,然后google之,出来的结果基本都是讲解VMware里面上网问题,我这种能网上却ping不出去的没有人提,或许这种淡疼的问题别人不屑提,又或者大家看到能上网就OK,管它ping通不通的,没这个需求,结果是鄙人这个情况在网上未找到满意的答案,也为找到这种例子,根据网上的做法,看了一眼resolv.conf这个文件,如下:
cy@cy:~$ cat -n /etc/resolv.conf 1 # Generated by NetworkManager 2 domain localdomain 3 search localdomain 4 nameserver 192.168.16.2 cy@cy:~$
没有任何问题,故只能自己淡淡的思考和尝试。
在摸索一阵之后发现了问题的所在,在与win7下本地网络的共享打开了,打开和关闭影响着VMware里面的Ubuntu上网问题,也影响着里面的ping同到外网问题,在Ubuntu不能ping同外网时,我的设置是这样的,如图
然后去掉共享,就能ping通到外网了,即在这种情况下
是用ping的结果为:
cy@cy:~$ ping www.baidu.com PING www.a.shifen.com (115.239.210.26) 56(84) bytes of data. 64 bytes from 115.239.210.26: icmp_req=1 ttl=128 time=47.6 ms 64 bytes from 115.239.210.26: icmp_req=2 ttl=128 time=48.5 ms 64 bytes from 115.239.210.26: icmp_req=3 ttl=128 time=48.9 ms ^C64 bytes from 115.239.210.26: icmp_req=4 ttl=128 time=48.7 ms --- www.a.shifen.com ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 15313ms rtt min/avg/max/mdev = 47.649/48.482/48.977/0.552 ms cy@cy:~$
到此已解决了上面的问题!
3.背景
在这里再来小小的补充一下产生这个需求的背景(即在可以上网的情况下,干嘛还要淡疼的非得用ping命令通了才罢休)。我想在VMware中的虚拟机中通过浏览器来上网的,这个需求应该非常之少,因为如果在VMware中用浏览器,还不如直接在Host机中用浏览器,这样软件运行的还更流畅一下,所以在VMware中一般只是作为一个网络是否连通的测试,既然测试网络连接,一般为了装的专业一点都会在shell下用命令来测试,当然说了这么多,这些都不是本文的需求目的,只是附带说一下而已。
本文的需求产生于要使用nmap命令来扫描一些端口,windows下的命令基本不熟,所以选择linux下的这些网络命令来满足需求,而这些东西用浏览器是代替不了的,所以才有了需要通过命令也能通到外网的需要。这里多啰嗦两句,本文例子中的外网的测试站点用的www.baidu.com,我想应该大家都很熟悉了,这让我想到了前段时间网上的说法,在我们这个镇上,一半人用他是用来搜索,一半人用他来测试网络连接。后面有哥们儿闲谈的时候跟我说到,很多用来测试网络连接,说明它的运维做的好,做这个网站的运维的人应该很自豪了。最后附上一张用nmap扫描的图:
2013-03-24 14:37