欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

linux下网络故障常用的几个命令

时间:2023-08-28
linux下网络故障常用的几个命令 ifconfig

ubuntu@VM-0-3-ubuntu:~$ ifconfigdocker0: flags=4099 mtu 1500       inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255       ether 02:42:49:13:91:23 txqueuelen 0 (Ethernet)       RX packets 0 bytes 0 (0.0 B)       RX errors 0 dropped 0 overruns 0 frame 0       TX packets 0 bytes 0 (0.0 B)       TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0​eth0: flags=4163 mtu 1500       inet 172.16.0.3 netmask 255.255.240.0 broadcast 172.16.15.255       inet6 fe80::5054:ff:fe9b:8405 prefixlen 64 scopeid 0x20       ether 52:54:00:9b:84:05 txqueuelen 1000 (Ethernet)       RX packets 48359052 bytes 4512423724 (4.5 GB)       RX errors 0 dropped 0 overruns 0 frame 0       TX packets 47191232 bytes 4195297257 (4.1 GB)       TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0​lo: flags=73 mtu 65536       inet 127.0.0.1 netmask 255.0.0.0       inet6 ::1 prefixlen 128 scopeid 0x10       loop txqueuelen 1000 (Local Loopback)       RX packets 1352984 bytes 110930762 (110.9 MB)       RX errors 0 dropped 0 overruns 0 frame 0       TX packets 1352984 bytes 110930762 (110.9 MB)       TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0​

可以方便的查看本机的几个网卡

ping

ubuntu@VM-0-3-ubuntu:~$ ping www.baidu.comPING www.a.shifen.com (14.215.177.39) 56(84) bytes of data.64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=54 time=2.88 ms64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=54 time=2.79 ms64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=54 time=2.78 ms64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=4 ttl=54 time=2.84 ms64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=5 ttl=54 time=2.90 ms^C--- www.a.shifen.com ping statistics ---5 packets transmitted, 5 received, 0% packet loss, time 4006msrtt min/avg/max/mdev = 2.781/2.837/2.898/0.047 ms​

可以查看目标机器是否ping通

telnet

ubuntu@VM-0-3-ubuntu:~$ telnet 127.0.0.1 3000Trying 127.0.0.1...Connected to 127.0.0.1.Escape character is '^]'.sfsdf

netstat

ubuntu@VM-0-3-ubuntu:~$ netstat -atnActive Internet connections (servers and established)Proto Recv-Q Send-Q Local Address           Foreign Address         Statetcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTENtcp        0      0 172.17.0.1:53           0.0.0.0:*               LISTENtcp        0      0 172.16.0.3:53           0.0.0.0:*               LISTENtcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTENtcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTENtcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTENtcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTENtcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTENtcp        0      0 127.0.0.1:953           0.0.0.0:*               LISTENtcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTENtcp        0      0 127.0.0.1:6011          0.0.0.0:*               LISTENtcp        0      0 127.0.0.1:6012          0.0.0.0:*               LISTENtcp        0      0 127.0.0.1:6013          0.0.0.0:*               LISTENtcp        0      0 172.16.0.3:111          206.81.10.86:58812     ESTABLISHEDtcp        0      0 172.16.0.3:22           183.198.11.196:21580   ESTABLISHEDtcp        0      0 127.0.0.1:3000          127.0.0.1:58318         TIME_WAITtcp        0      0 172.16.0.3:22           183.198.11.196:21602   ESTABLISHEDtcp        0      0 172.16.0.3:22           183.198.11.196:22039   ESTABLISHEDtcp        0      0 172.16.0.3:39816        169.254.0.55:5574       ESTABLISHEDtcp        0      0 172.16.0.3:111          192.3.116.182:46844     ESTABLISHEDtcp        0      0 172.16.0.3:22           183.198.11.196:22025   ESTABLISHEDtcp        0      0 172.16.0.3:111          170.130.187.34:51001   ESTABLISHEDtcp        0      0 172.16.0.3:22           183.198.11.196:22506   ESTABLISHEDtcp        0      0 172.16.0.3:50948        169.254.0.138:8086     ESTABLISHEDtcp        0      0 172.16.0.3:22           183.198.11.196:22495   ESTABLISHEDtcp        0      0 172.16.0.3:111          164.90.208.105:46554   ESTABLISHEDtcp        0      0 172.16.0.3:22           183.198.11.196:22453   ESTABLISHEDtcp        0   3360 172.16.0.3:22           183.198.11.196:22438   ESTABLISHEDtcp6       0      0 :::111                 :::*                   LISTENtcp6       0      0 ::1:53                 :::*                   LISTEN​

ubuntu@VM-0-3-ubuntu:~$ netstat -aunActive Internet connections (servers and established)Proto Recv-Q Send-Q Local Address           Foreign Address         Stateudp        0      0 172.17.0.1:53           0.0.0.0:*udp        0      0 172.16.0.3:53           0.0.0.0:*udp        0      0 127.0.0.1:53            0.0.0.0:*udp        0      0 127.0.0.53:53           0.0.0.0:*udp        0      0 172.16.0.3:68           0.0.0.0:*udp        0      0 0.0.0.0:111             0.0.0.0:*udp        0      0 127.0.0.1:123           0.0.0.0:*udp        0      0 172.16.0.3:123          0.0.0.0:*udp6       0      0 fe80::5054:ff:fe9b:8:53 :::*udp6       0      0 ::1:53                 :::*udp6       0      0 :::111                 :::*udp6       0      0 ::1:123                 :::*udp6       0      0 fe80::5054:ff:fe9b::123 :::*​

lsof

root@VM-0-3-ubuntu:/home/ubuntu# lsof -i -Pn | grep "3000"epoll_ser 637850           root   3u IPv4 48974473     0t0 TCP *:3000 (LISTEN)epoll_ser 640784           root   3u IPv4 48991331     0t0 TCP *:3000 (LISTEN)​

nc

ubuntu@VM-0-3-ubuntu:~$ nc -v 127.0.0.1 3000 # tcp 连接上去Connection to 127.0.0.1 3000 port [tcp/*] succeeded!​root@VM-0-3-ubuntu:/home/ubuntu/mybooksources-master/Chapter04/code# nc -v -l 127.0.0.1 3001 # 监听一个端口Listening on localhost 3001Connection received on localhost 39630​root@VM-0-3-ubuntu:/home/ubuntu/mybooksources-master/Chapter04/code# nc -v -l -u 127.0.0.1 3001 # 监听一个udp端口Bound on localhost 3001Connection received on localhost 50632XXXXXdfdfsdfsdf​ubuntu@VM-0-3-ubuntu:~$ nc -v -u 127.0.0.1 3001  # 连接udpdfdfConnection to 127.0.0.1 3001 port [udp/*] succeeded!sdfsdf​

curl

ubuntu@VM-0-3-ubuntu:~$ curl www.baidu.com 百度一下,你就知道 新闻 hao123 地图 视频 贴吧 更多产品

关于百度 about Baidu

©2017Baidu使用百度前必读 意见反馈京ICP证030173号

tcpdump

root@VM-0-3-ubuntu:/home/ubuntu# tcpdump -i any "tcp port 3001"tcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on any, link-type LINUX_SLL (Linux cooked v1), capture size 262144 bytes19:56:12.928329 IP localhost.39946 > localhost.3001: Flags [S], seq 2726208034, win 65495, options [mss 65495,sackOK,TS val 2359419880 ecr 0,nop,wscale 7], length 019:56:12.928341 IP localhost.3001 > localhost.39946: Flags [S.], seq 3476933863, ack 2726208035, win 65483, options [mss 65495,sackOK,TS val 2359419880 ecr 2359419880,nop,wscale 7], length 019:56:12.928350 IP localhost.39946 > localhost.3001: Flags [.], ack 1, win 512, options [nop,nop,TS val 2359419880 ecr 2359419880], length 0​# 以上是抓包三次握手

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。