首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >杂谈:ubuntu检查网络状态命令

杂谈:ubuntu检查网络状态命令

作者头像
CV_Learner
修改2019-12-10 18:47:24
3.3K0
修改2019-12-10 18:47:24
举报
文章被收录于专栏:CV_LearnCV_Learn

参考博客:https://blog.csdn.net/yph001/article/details/80177154

https://blog.csdn.net/gaoganghua/article/details/80386107

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通,则表面路由器与外网通信存在问题

感谢原文作者@yph001 https://blog.csdn.net/yph001/article/details/80177154

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 二、检测网络状态的完整测试过程
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档