一、主要内容
本文主要讲解Ubuntu下的网络故障排查方法。
(1)查看网络监听端口
bash
tian@tian-hang:~$ sudo ss -tunlp
[sudo] password for tian:
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
udp UNCONN 0 0 0.0.0.0:56808 0.0.0.0:* users:(("avahi-daemon",pid=1009,fd=14))
udp UNCONN 0 0 127.0.0.54:53 0.0.0.0:* users:(("systemd-resolve",pid=812,fd=16))
udp UNCONN 0 0 127.0.0.53%lo:53 0.0.0.0:* users:(("systemd-resolve",pid=812,fd=14))
udp UNCONN 0 0 0.0.0.0:5353 0.0.0.0:* users:(("avahi-daemon",pid=1009,fd=12))
udp UNCONN 0 0 [::]:38033 [::]:* users:(("avahi-daemon",pid=1009,fd=15))
udp UNCONN 0 0 [::]:5353 [::]:* users:(("avahi-daemon",pid=1009,fd=13))
tcp LISTEN 0 4096 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=1767,fd=3),("systemd",pid=1,fd=259))
tcp LISTEN 0 128 127.0.0.1:6010 0.0.0.0:* users:(("sshd",pid=1831,fd=8))
tcp LISTEN 0 4096 127.0.0.1:631 0.0.0.0:* users:(("cupsd",pid=1314,fd=7))
tcp LISTEN 0 4096 127.0.0.54:53 0.0.0.0:* users:(("systemd-resolve",pid=812,fd=17))
tcp LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:* users:(("systemd-resolve",pid=812,fd=15))
tcp LISTEN 0 4096 [::]:22 [::]:* users:(("sshd",pid=1767,fd=4),("systemd",pid=1,fd=260))
tcp LISTEN 0 128 [::1]:6010 [::]:* users:(("sshd",pid=1831,fd=7))
tcp LISTEN 0 4096 [::1]:631 [::]:* users:(("cupsd",pid=1314,fd=6))
ss是Ubuntu系统自带的命令;Ubuntu中还有类似的命令netstat;都是用来查看网络状态的,netstat需要安装,属于net-tool工具里面的。它是比较古老的Ubuntu命令,现代建议使用ss。
命令解析:
-t:TCP 连接
-u:UDP 连接
-n:数字端口,不解析域名 / 服务名
-l:只看监听端口(本地服务)
-p:显示占用端口的进程 PID / 程序名(需要 root/sudo)