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的一些题的题解,有兴趣的可以看看。