-t tpcduank
-u udp端口
-p port 端口
-l listen 监听
-an 查看所有连接状态
ss -an与netstat类似,但不能查看进程名
netstat -an | awk ‘/^tcp/ {++sta[$NF]} END {for(key in sta) print key,"\t",sta[key]}’ 查看当前系统tcp三次握手不同状态总数值
#截取部分信息
[root@localhost ~]# netstat
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 52 localhost.localdoma:ssh 192.168.131.1:5549 ESTABLISHED
tcp 0 0 localhost.localdoma:ssh 192.168.131.1:13681 ESTABLISHED
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node Path
unix 3 [ ] DGRAM 9493 /run/systemd/notify
unix 2 [ ] DGRAM 9495 /run/systemd/cgroups-agent
unix 5 [ ] DGRAM 9506 /run/systemd/journal/socket
unix 25 [ ] DGRAM 9508 /dev/log
unix 2 [ ] DGRAM 20579 /var/run/chrony/chronyd.sock
unix 2 [ ] DGRAM 13814 /run/systemd/shutdownd
unix 3 [ ] STREAM CONNECTED 35855
unix 3 [ ] STREAM CONNECTED 21521
unix 3 [ ] STREAM CONNECTED 17391 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 34450 @/tmp/.X11-unix/X0
unix 3 [ ] STREAM CONNECTED 27551
unix 3 [ ] STREAM CONNECTED 34534 /run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 34752 /run/dbus/system_bus_socket
[root@localhost ~]# netstat -lnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 1150/python
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1685/master
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2133/mysqld
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1863/dnsmasq
tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN 1070/pure-ftpd (SER
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1019/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1023/cupsd
tcp6 0 0 :::18168 :::* LISTEN 1185/httpd
tcp6 0 0 :::888 :::* LISTEN 1185/httpd
tcp6 0 0 ::1:25 :::* LISTEN 1685/master
tcp6 0 0 :::10086 :::* LISTEN 1185/httpd
tcp6 0 0 :::80 :::* LISTEN 1185/httpd
tcp6 0 0 :::21 :::* LISTEN 1070/pure-ftpd (SER
tcp6 0 0 :::22 :::* LISTEN 1019/sshd
tcp6 0 0 ::1:631 :::* LISTEN 1023/cupsd
udp 0 0 0.0.0.0:5353 0.0.0.0:* 699/avahi-daemon: r
udp 0 0 127.0.0.1:323 0.0.0.0:* 731/chronyd
udp 0 0 192.168.122.1:53 0.0.0.0:* 1863/dnsmasq
udp 0 0 0.0.0.0:67 0.0.0.0:* 1863/dnsmasq
udp 0 0 0.0.0.0:54371 0.0.0.0:* 699/avahi-daemon: r
udp6 0 0 ::1:323 :::* 731/chronyd
raw6 0 0 :::58 :::* 7 733/NetworkManager
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node PID/Program name Path
unix 2 [ ACC ] STREAM LISTENING 33702 2464/gnome-session- @/tmp/.ICE-unix/2464
unix 2 [ ACC ] STREAM LISTENING 13832 1/systemd /run/lvm/lvmpolld.socket
unix 2 [ ACC ] STREAM LISTENING 9503 1/systemd /run/systemd/journal/stdout
unix 2 [ ACC ] STREAM LISTENING 27561 1685/master private/smtp
unix 2 [ ACC ] STREAM LISTENING 27342 1486/X @/tmp/.X11-unix/X0
unix 2 [ ACC ] STREAM LISTENING 33703 2464/gnome-session- /tmp/.ICE-unix/2464
unix 2 [ ACC ] STREAM LISTENING 13863 1/systemd /run/lvm/lvmetad.socket
unix 2 [ ACC ] STREAM LISTENING 27343 1486/X /tmp/.X11-unix/X0
unix 2 [ ACC ] STREAM LISTENING 27542 1685/master private/defer
unix 2 [ ACC ] STREAM LISTENING 33621 2628/ssh-agent /tmp/ssh-bt0ivsRH0T8f/agent.2464
unix 2 [ ACC ] STREAM LISTENING 27546 1685/master private/trace
unix 2 [ ACC ] STREAM LISTENING 27549 1685/master private/verify
unix 2 [ ACC ] STREAM LISTENING 27555 1685/master private/proxymap
unix 2 [ ACC ] STREAM LISTENING 27558 1685/master private/proxywrite
unix 2 [ ACC ] STREAM LISTENING 27565 1685/master private/relay
unix 2 [ ACC ] STREAM LISTENING 27571 1685/master private/error
unix 2 [ ACC ] STREAM LISTENING 34248 2808/pulseaudio /tmp/.esd-0/socket
#截取部分
[root@localhost ~]# netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 52 192.168.131.128:22 192.168.131.1:5549 ESTABLISHED
tcp 0 0 192.168.131.128:22 192.168.131.1:13681 ESTABLISHED
tcp6 0 0 :::18168 :::* LISTEN
tcp6 0 0 :::888 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
tcp6 0 0 :::10086 :::* LISTEN
tcp6 0 0 :::80 :::* LISTEN
tcp6 0 0 :::21 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:631 :::* LISTEN
udp 0 0 0.0.0.0:5353 0.0.0.0:*
udp 0 0 127.0.0.1:323 0.0.0.0:*
udp 0 0 192.168.122.1:53 0.0.0.0:*
udp 0 0 0.0.0.0:67 0.0.0.0:*
udp 0 0 0.0.0.0:54371 0.0.0.0:*
udp6 0 0 ::1:323 :::*
raw6 0 0 :::58 :::* 7
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 33702 @/tmp/.ICE-unix/2464
unix 2 [ ACC ] STREAM LISTENING 13832 /run/lvm/lvmpolld.socket
unix 3 [ ] DGRAM 9493 /run/systemd/notify
unix 2 [ ] DGRAM 9495 /run/systemd/cgroups-agent
unix 2 [ ACC ] STREAM LISTENING 9503 /run/systemd/journal/stdout
unix 2 [ ACC ] STREAM LISTENING 27561 private/smtp
unix 2 [ ACC ] STREAM LISTENING 27342 @/tmp/.X11-unix/X0
unix 5 [ ] DGRAM 9506 /run/systemd/journal/socket
unix 2 [ ACC ] STREAM LISTENING 33703 /tmp/.ICE-unix/2464
unix 25 [ ] DGRAM 9508 /dev/log
unix 2 [ ACC ] STREAM LISTENING 13863 /run/lvm/lvmetad.socket
unix 2 [ ACC ] STREAM LISTENING 27343 /tmp/.X11-unix/X0
unix 2 [ ACC ] STREAM LISTENING 27542 private/defer
unix 2 [ ACC ] STREAM LISTENING 33621 /tmp/ssh-bt0ivsRH0T8f/agent.2464
unix 2 [ ACC ] STREAM LISTENING 27546 private/trace
unix 2 [ ACC ] STREAM LISTENING 27549 private/verify
unix 2 [ ACC ] STREAM LISTENING 27555 private/proxymap
unix 2 [ ACC ] STREAM LISTENING 27558 private/proxywrite
unix 2 [ ACC ] STREAM LISTENING 27565 private/relay
unix 2 [ ACC ] STREAM LISTENING 27571 private/error
unix 2 [ ACC ] STREAM LISTENING 34248 /tmp/.esd-0/socket
unix 2 [ ACC ] STREAM LISTENING 27574 private/retry
unix 2 [ ACC ] STREAM LISTENING 27577 private/discard
unix 2 [ ACC ] STREAM LISTENING 27580 private/local
unix 2 [ ACC ] STREAM LISTENING 19003 /var/run/abrt/abrt.socket
unix 2 [ ACC ] STREAM LISTENING 27583 private/virtual
unix 2 [ ACC ] STREAM LISTENING 27586 private/lmtp
unix 2 [ ACC ] STREAM LISTENING 27589 private/anvil
unix 2 [ ACC ] STREAM LISTENING 33306 @/tmp/dbus-RVljlinlql
unix 2 [ ACC ] STREAM LISTENING 27528 public/qmgr
unix 2 [ ACC ] STREAM LISTENING 20633 /var/lib/gssproxy/default.sock
unix 2 [ ACC ] STREAM LISTENING 18598 @ISCSID_UIP_ABSTRACT_NAMESPACE
unix 2 [ ACC ] STREAM LISTENING 36994 @/tmp/dbus-6awdtCmj
unix 2 [ ] DGRAM 20579 /var/run/chrony/chronyd.sock
unix 2 [ ACC ] STREAM LISTENING 32312 @/tmp/dbus-Bb0YJI2oT7
unix 2 [ ACC ] STREAM LISTENING 27552 public/flush
unix 2 [ ACC ] SEQPACKET LISTENING 13949 /run/udev/control
[root@localhost ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 1150/python
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1685/master
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2133/mysqld
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1863/dnsmasq
tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN 1070/pure-ftpd (SER
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1019/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1023/cupsd
tcp6 0 0 :::18168 :::* LISTEN 1185/httpd
tcp6 0 0 :::888 :::* LISTEN 1185/httpd
tcp6 0 0 ::1:25 :::* LISTEN 1685/master
tcp6 0 0 :::10086 :::* LISTEN 1185/httpd
tcp6 0 0 :::80 :::* LISTEN 1185/httpd
tcp6 0 0 :::21 :::* LISTEN 1070/pure-ftpd (SER
tcp6 0 0 :::22 :::* LISTEN 1019/sshd
tcp6 0 0 ::1:631 :::* LISTEN 1023/cupsd
[root@localhost ~]# netstat -lnup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
udp 0 0 0.0.0.0:5353 0.0.0.0:* 699/avahi-daemon: r
udp 0 0 127.0.0.1:323 0.0.0.0:* 731/chronyd
udp 0 0 192.168.122.1:53 0.0.0.0:* 1863/dnsmasq
udp 0 0 0.0.0.0:67 0.0.0.0:* 1863/dnsmasq
udp 0 0 0.0.0.0:54371 0.0.0.0:* 699/avahi-daemon: r
udp6 0 0 ::1:323 :::* 731/chronyd
[root@localhost ~]# netstat -an | awk '/^tcp/ {++sta[$NF]} END {for(key in sta) print key,"\t",sta[key]}'
LISTEN 15
ESTABLISHED 2
#LISTEN
#ESTABLISHED 保持连接正在传输数据,数值上千时负责满载。
#TIME_WAIT 通讯完毕但未断开
#FIN_WAIT1
#FIN_WAIT2
#SYN_RECV
#CLOSING
#LAST_ACK
ss -an
监听所有端口
[root@localhost ~]# ss -an
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
nl UNCONN 0 0 0:2744 *
nl UNCONN 0 0 0:3109 *
nl UNCONN 0 0 0:276825115 *
nl UNCONN 0 0 0:2292 *
nl UNCONN 0 0 0:0 *
nl UNCONN 0 0 0:3254 *
nl UNCONN 0 0 0:2731 *
nl UNCONN 0 0 0:-1291844581 *
nl UNCONN 0 0 0:-1300233507 *
nl UNCONN 0 0 0:3038 *
nl UNCONN 0 0 0:2936 *
nl UNCONN 0 0 0:1849 *
nl UNCONN 0 0 0:699 *
nl UNCONN 0 0 0:3254 *
nl UNCONN 0 0 0:2936 *
nl UNCONN 0 0 0:3109 *
nl UNCONN 0 0 0:3038 *
nl UNCONN 0 0 0:2744 *
nl UNCONN 0 0 0:2731 *
nl UNCONN 0 0 0:2292 *
nl UNCONN 0 0 0:1849 *
nl UNCONN 0 0 0:-1300233507 *
nl UNCONN 0 0 0:699 *
nl UNCONN 4352 0 4:5659 *
nl UNCONN 768 0 4:0 *
nl UNCONN 0 0 6:0 *
nl UNCONN 0 0 7:0 *
nl UNCONN 0 0 9:2449 *
nl UNCONN 0 0 9:0 *
nl UNCONN 0 0 9:672 *
nl UNCONN 0 0 9:1 *
nl UNCONN 0 0 10:0 *
nl UNCONN 0 0 11:0 *
nl UNCONN 0 0 15:0 *
nl UNCONN 0 0 15:2681 *
nl UNCONN 0 0 15:1486 *
nl UNCONN 0 0 15:-4122 *
nl UNCONN 0 0 15:2808 *
nl UNCONN 0 0 15:-4126 *
nl UNCONN 0 0 15:-4123 *
nl UNCONN 0 0 15:2762 *
nl UNCONN 0 0 15:507 *
nl UNCONN 0 0 15:2780 *
nl UNCONN 0 0 15:1051 *
nl UNCONN 0 0 15:-4136 *
nl UNCONN 0 0 15:-440400869 *
nl UNCONN 0 0 15:-4109 *
nl UNCONN 0 0 15:-4121 *
nl UNCONN 0 0 15:722 *
nl UNCONN 0 0 15:733 *
nl UNCONN 0 0 15:1 *
nl UNCONN 0 0 15:744 *
nl UNCONN 0 0 15:-4124 *
nl UNCONN 0 0 15:2213 *
nl UNCONN 0 0 15:2791 *
nl UNCONN 0 0 15:2381 *
nl UNCONN 0 0 15:1021 *
nl UNCONN 0 0 15:-4125 *
nl UNCONN 0 0 15:-4135 *
nl UNCONN 0 0 15:2873 *
nl UNCONN 0 0 15:2873 *
nl UNCONN 0 0 15:2808 *
nl UNCONN 0 0 15:2791 *
nl UNCONN 0 0 15:2780 *
nl UNCONN 0 0 15:2762 *
nl UNCONN 0 0 15:2681 *
nl UNCONN 0 0 15:-4136 *
nl UNCONN 0 0 15:-4135 *
nl UNCONN 0 0 15:2381 *
nl UNCONN 0 0 15:2213 *
nl UNCONN 0 0 15:-4126 *
nl UNCONN 0 0 15:1486 *
nl UNCONN 0 0 15:1021 *
nl UNCONN 0 0 15:1051 *
nl UNCONN 0 0 15:-440400869 *
nl UNCONN 0 0 15:-4125 *
nl UNCONN 0 0 15:-4124 *
nl UNCONN 0 0 15:733 *
nl UNCONN 0 0 15:722 *
nl UNCONN 0 0 15:-4123 *
nl UNCONN 0 0 15:-4122 *
nl UNCONN 0 0 15:-4121 *
nl UNCONN 0 0 15:744 *
nl UNCONN 0 0 15:-4109 *
nl UNCONN 0 0 15:1 *
nl UNCONN 0 0 16:0 *
nl UNCONN 0 0 18:0 *
u_str LISTEN 0 128 @/tmp/.ICE-unix/2464 33702 * 0
u_str LISTEN 0 128 /run/lvm/lvmpolld.socket 13832 * 0
u_dgr UNCONN 0 0 /run/systemd/notify 9493 * 0
u_dgr UNCONN 0 0 /run/systemd/cgroups-agent 9495 * 0
u_str LISTEN 0 128 /run/systemd/journal/stdout 9503 * 0
u_str LISTEN 0 100 private/smtp 27561 * 0
u_str LISTEN 0 128 @/tmp/.X11-unix/X0 27342 * 0
u_dgr UNCONN 0 0 /run/systemd/journal/socket 9506 * 0
u_str LISTEN 0 128 /tmp/.ICE-unix/2464 33703 * 0
u_dgr UNCONN 0 0 /dev/log 9508 * 0
u_str LISTEN 0 128 /run/lvm/lvmetad.socket 13863 * 0
u_str LISTEN 0 128 /tmp/.X11-unix/X0 27343 * 0
u_str LISTEN 0 100 private/defer 27542 * 0
u_str LISTEN 0 128 /tmp/ssh-bt0ivsRH0T8f/agent.2464 33621 * 0
u_str LISTEN 0 100 private/trace 27546 * 0
u_str LISTEN 0 100 private/verify 27549 * 0
u_str LISTEN 0 100 private/proxymap 27555 * 0
u_str LISTEN 0 100 private/proxywrite 27558 * 0
u_str LISTEN 0 100 private/relay 27565 * 0
u_str LISTEN 0 100 private/error 27571 * 0
u_str LISTEN 0 5 /tmp/.esd-0/socket 34248 * 0
u_str LISTEN 0 100 private/retry 27574 * 0
u_str LISTEN 0 100 private/discard 27577 * 0
u_str LISTEN 0 100 private/local 27580 * 0
u_str LISTEN 0 10 /var/run/abrt/abrt.socket 19003 * 0
u_str LISTEN 0 100 private/virtual 27583 * 0
u_str LISTEN 0 100 private/lmtp 27586 * 0
u_str LISTEN 0 100 private/anvil 27589 * 0
u_str LISTEN 0 128 @/tmp/dbus-RVljlinlql 33306 * 0
u_str LISTEN 0 100 public/qmgr 27528 * 0
u_str LISTEN 0 10 /var/lib/gssproxy/default.sock 20633 * 0
u_str LISTEN 0 128 @ISCSID_UIP_ABSTRACT_NAMESPACE 18598 * 0
u_str LISTEN 0 10 @/tmp/dbus-6awdtCmj 36994 * 0