Linux网络命令

Linux网络命令

1、ping 命令

使用命令:ping [-c 次数]网址或者IP地址。可以查看当前客户端与IP的网络是否可达。

ping -c 5 www.baidu.com
PING www.a.shifen.com (157.148.69.74) 56(84) bytes of data.
64 bytes from 157.148.69.74 (157.148.69.74): icmp_seq=1 ttl=52 time=3.69 ms
64 bytes from 157.148.69.74 (157.148.69.74): icmp_seq=2 ttl=52 time=3.57 ms
64 bytes from 157.148.69.74 (157.148.69.74): icmp_seq=3 ttl=52 time=3.57 ms
64 bytes from 157.148.69.74 (157.148.69.74): icmp_seq=4 ttl=52 time=3.61 ms
64 bytes from 157.148.69.74 (157.148.69.74): icmp_seq=5 ttl=52 time=3.62 ms

--- www.a.shifen.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4005ms
rtt min/avg/max/mdev = 3.570/3.612/3.689/0.043 ms

-c选项也可以省略:

ping www.baidu.com
PING www.a.shifen.com (157.148.69.74) 56(84) bytes of data.
64 bytes from 157.148.69.74 (157.148.69.74): icmp_seq=1 ttl=52 time=3.48 ms
64 bytes from 157.148.69.74 (157.148.69.74): icmp_seq=2 ttl=52 time=3.47 ms
64 bytes from 157.148.69.74 (157.148.69.74): icmp_seq=3 ttl=52 time=3.71 ms
64 bytes from 157.148.69.74 (157.148.69.74): icmp_seq=4 ttl=52 time=3.52 ms
64 bytes from 157.148.69.74 (157.148.69.74): icmp_seq=5 ttl=52 time=3.58 ms
64 bytes from 157.148.69.74 (157.148.69.74): icmp_seq=6 ttl=52 time=3.63 ms
64 bytes from 157.148.69.74 (157.148.69.74): icmp_seq=7 ttl=52 time=4.07 ms
^C
--- www.a.shifen.com ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 6009ms
rtt min/avg/max/mdev = 3.468/3.635/4.074/0.195 ms

如果显示0 received, 100% packet loss,说明目标IP网络不可达。

ping 192.168.3.12
PING 192.168.3.12 (192.168.3.12) 56(84) bytes of data.
^C
--- 192.168.3.12 ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 3064ms

2、netstat命令

使用命令:netstat [选项],可以查看网络状态。

常用选项:

  • -n 拒绝显示别名,能显示数字的全部转化成数字

  • -l 仅列出有在 Listen (监听) 的服务状态

  • -p 显示建立相关链接的程序名

  • -t (tcp)仅显示 tcp 相关选项

  • -u (udp)仅显示 udp 相关选项

  • -a (all)显示所有选项,默认不显示 Listen 相关

还可以使用watch命令每隔一段时间查看一次网络状态:

//每个 1s 执行一次 netstat -npua
xp2@VM-8-12-ubuntu:~/Linux_Advance/day_01/demo_01/udp_server_echo$ watch -n 1 netstat -npua


3、pidof

使用命令:pidod 进程名,通过进程名查看进程pid。

xp2@VM-8-12-ubuntu:~/Linux_Advance/day_01/demo_01/udp_server_echo$ pidof udp_server 
222863


OKOK,Linux网络命令就到这里,如果你对Linux和C++也感兴趣的话,可以看看我的主页哦。下面是我的github主页,里面记录了我的学习代码和leetcode的一些题的题解,有兴趣的可以看看。

Xpccccc的github主页

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Xpccccc

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值