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:~$ ifconfigeth0 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=55Reply from 115.239.210.27: bytes=32 time=48ms TTL=55Reply from 115.239.210.27: bytes=32 time=47ms TTL=55Reply 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=64Reply from 192.168.16.151: bytes=32 time<1ms TTL=64Reply from 192.168.16.151: bytes=32 time<1ms TTL=64Reply 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.1PING 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 ms64 bytes from 192.168.16.1: icmp_req=2 ttl=64 time=0.469 ms64 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 2005msrtt min/avg/max/mdev = 0.469/0.711/1.169/0.324 ms cy@cy:~$ ping 192.168.1.25PING 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 ms64 bytes from 192.168.1.25: icmp_req=2 ttl=128 time=1.36 ms64 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 2005msrtt min/avg/max/mdev = 1.195/1.290/1.363/0.081 ms
6.結果,從Ubuntu不能ping 到外網去:
cy@cy:~$ ping www.baidu.comPING 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.2cy@cy:~$
沒有任何問題,故只能自己淡淡的思考和嘗試。
在摸索一陣之後發現了問題的所在,在與win7下本網的共用開啟了,開啟和關閉影響著VMware裡面的Ubuntu上網問題,也影響著裡面的ping同到外網問題,在Ubuntu不能ping同外網時,我的設定是這樣的,
然後去掉共用,就能ping通到外網了,即在這種情況下
是用ping的結果為:
cy@cy:~$ ping www.baidu.comPING 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 ms64 bytes from 115.239.210.26: icmp_req=2 ttl=128 time=48.5 ms64 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 15313msrtt min/avg/max/mdev = 47.649/48.482/48.977/0.552 mscy@cy:~$
到此已解決了上面的問題!
3.背景
在這裡再來小小的補充一下產生這個需求的背景(即在可以上網的情況下,幹嘛還要淡疼的非得用ping命令通了才罷休)。我想在VMware中的虛擬機器中通過瀏覽器來上網的,這個需求應該非常之少,因為如果在VMware中用瀏覽器,還不如直接在Host機中用瀏覽器,這樣軟體啟動並執行還更流暢一下,所以在VMware中一般只是作為一個網路是否連通的測試,既然測試網路連接,一般為了裝的專業一點都會在shell下用命令來測試,當然說了這麼多,這些都不是本文的需求目的,只是附帶說一下而已。
本文的需求產生於要使用nmap命令來掃描一些連接埠,windows下的命令基本不熟,所以選擇linux下的這些網路命令來滿足需求,而這些東西用瀏覽器是代替不了的,所以才有了需要通過命令也能通到外網的需要。這裡多囉嗦兩句,本文例子中的外網的測試網站用的www.baidu.com,我想應該大家都很熟悉了,這讓我想到了前段時間網上的說法,在我們這個鎮上,一半人用他是用來搜尋,一半人用他來測試網路連接。後面有哥們兒閑談的時候跟我說到,很多用來測試網路連接,說明它的營運做的好,做這個網站的營運的人應該很自豪了。最後附上一張用nmap掃描的圖:
2013-03-24 14:37