1. 程式人生 > >ubuntu 檢測網路狀態命令

ubuntu 檢測網路狀態命令

一、檢測網路狀態常用的基本命令

1)ifconfig命令被用於配置和顯示Linux核心中網路介面的網路引數

ifconfig

輸出結果如下:

drew@ubun:~$ ifconfig
eth0      Link encap:乙太網  硬體地址 d0:17:c2:aa:11:b8  
          inet 地址:10.0.4.33  廣播:10.0.31.255  掩碼:255.255.224.0
          inet6 地址: fe80::d217:c2ff:feaa:11b8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST
MTU:1500 躍點數:1 接收資料包:597503 錯誤:0 丟棄:0 過載:0 幀數:0 傳送資料包:123369 錯誤:0 丟棄:0 過載:0 載波:0 碰撞:0 傳送佇列長度:1000 接收位元組:608806060 (608.8 MB) 傳送位元組:11350655 (11.3 MB) lo Link encap:本地環回 inet 地址:127.0.0.1 掩碼:255.0.0.0 inet6 地址: ::1/128 Scope:Host UP LOOPBACK RUNNING
MTU:65536 躍點數:1 接收資料包:2488 錯誤:0 丟棄:0 過載:0 幀數:0 傳送資料包:2488 錯誤:0 丟棄:0 過載:0 載波:0 碰撞:0 傳送佇列長度:0 接收位元組:259564 (259.5 KB) 傳送位元組:259564 (259.5 KB)

2)使用nm-tool來檢視檢視IP,閘道器,DNS

nm-tool

輸出結果為:

drew@ubun:~$ nm-tool

NetworkManager Tool

State: connected (global)

- Device
: eth0 [有線連線 1] ----------------------------------------------- Type: Wired Driver: r8169 State: connected Default: yes HW Address: D0:17:C2:AA:11:B8 Capabilities: Carrier Detect: yes Speed: 1000 Mb/s Wired Properties Carrier: on IPv4 Settings: Address: 10.0.4.33 Prefix: 19 (255.255.224.0) Gateway: 10.0.0.1 DNS: 119.29.29.29 DNS: 119.28.28.28

3)檢視核心 IP 路由表

netstat -rn

輸出結果為:

drew@ubun:~$ netstat -rn
核心 IP 路由表
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         10.0.0.1        0.0.0.0         UG        0 0          0 eth0
10.0.0.0        0.0.0.0         255.255.224.0   U         0 0          0 eth0

二、檢測網路狀態的完整測試過程

- 網路通訊的基本流程
         路由器A ================================路由器B

           |                 INTERNET              |        

           |                                       |

        交換機A                                   交換機B

        |    |                                   |    |

        |    |                                   |    |
      PC-A    PC-B                              PC-C   PC-D         

其中,一般來說,路由器的LAN介面的IP地址就是你所在區域網中的閘道器,是連線內網和外網用的裝置。

- 網路通訊測試的基本流程
  • ping 閘道器IP:檢測主機到閘道器之前是否能夠正常通訊
drew@ubun:~$ ping -c 3 10.0.0.1
PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.
64 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=0.174 ms
64 bytes from 10.0.0.1: icmp_seq=2 ttl=64 time=0.170 ms
64 bytes from 10.0.0.1: icmp_seq=3 ttl=64 time=0.135 ms

--- 10.0.0.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1998ms
rtt min/avg/max/mdev = 0.135/0.159/0.174/0.022 ms
  • ping DNS域名伺服器,檢測能夠正常通訊,其中DNS地址通過上面&nm -tool已經能找到
drew@ubun:~$ ping -c 3 119.28.28.28
PING 119.28.28.28 (119.28.28.28) 56(84) bytes of data.
64 bytes from 119.28.28.28: icmp_seq=1 ttl=44 time=38.6 ms
64 bytes from 119.28.28.28: icmp_seq=2 ttl=44 time=38.8 ms
64 bytes from 119.28.28.28: icmp_seq=3 ttl=44 time=38.6 ms

--- 119.28.28.28 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 38.627/38.704/38.810/0.239 ms

  • ping 外網地址,檢測到能夠與外網正常通訊
drew@ubun:~$ ping www.baidu.com
PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38: icmp_seq=1 ttl=56 time=5.95 ms
64 bytes from 14.215.177.38: icmp_seq=2 ttl=56 time=5.86 ms
64 bytes from 14.215.177.38: icmp_seq=3 ttl=56 time=5.73 ms
64 bytes from 14.215.177.38: icmp_seq=4 ttl=56 time=6.05 ms
64 bytes from 14.215.177.38: icmp_seq=5 ttl=56 time=8.03 ms
64 bytes from 14.215.177.38: icmp_seq=6 ttl=56 time=5.94 ms
^C
--- www.a.shifen.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5007ms
rtt min/avg/max/mdev = 5.738/6.265/8.034/0.799 ms
  • 結果分析
    • 當到閘道器之間ping不通,則更多的是主機到路由器連線的問題
    • 當到DNS之間ping不通,則更多的是域名解析伺服器出現了問題
    • 當到外網不通,而前面兩項都能夠ping通,則表面路由器與外網通訊存在問題