VMware中的linux能上網不能ping通的可能偏方一


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM