【命令星级】 ★★★★★
【功能说明】
netstat命令用于显示本机网络的连接状态、运行端口和路由表等信息。
【语法格式】
netstat [option]
netstat [选项]
**说明:**在netstat命令及后面的选项里,每个元素直接都至少要有一个空格。
【选项说明】
表10-6针对该命令的参数选项进行了说明。
表10-6 netstat命令的参数选项及说明
**范例10-25:**常用选项组合(一)。
[root@centos7 ~]# netstat -an #常用组合-a和-n,显示所有的连接信息。
Active Internet connections (servers and established) #活动的TCP/IP网络连接。
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 52 10.0.0.201:22 10.0.0.1:61194 ESTABLISHED
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
raw6 0 0 :::58 :::* 7
Active UNIX domain sockets (servers and established) #活动的unix socket连接。
Proto RefCnt Flags Type State I-Node Path
unix 3 [ ] DGRAM 8965 /run/systemd/notify
unix 2 [ ] DGRAM 8967 /run/systemd/cgroups-agent
unix 2 [ ACC ] STREAM LISTENING 23064 private/tlsmgr
unix 2 [ ACC ] STREAM LISTENING 23067 private/rewrite
unix 2 [ ACC ] STREAM LISTENING 23070 private/bounce
unix 2 [ ACC ] STREAM LISTENING 23085 private/proxymap
unix 2 [ ACC ] STREAM LISTENING 8985 /run/systemd/journal/stdout
unix 2 [ ACC ] STREAM LISTENING 23088 private/proxywrite
unix 2 [ ACC ] STREAM LISTENING 23091 private/smtp
unix 5 [ ] DGRAM 8988 /run/systemd/journal/socket
unix 2 [ ACC ] STREAM LISTENING 23094 private/relay
unix 2 [ ACC ] STREAM LISTENING 23100 private/error
unix 13 [ ] DGRAM 8990 /dev/log
unix 2 [ ACC ] STREAM LISTENING 23103 private/retry
unix 2 [ ACC ] STREAM LISTENING 23106 private/discard
unix 2 [ ACC ] STREAM LISTENING 23109 private/local
unix 2 [ ACC ] STREAM LISTENING 23112 private/virtual
unix 2 [ ACC ] STREAM LISTENING 23115 private/lmtp
unix 2 [ ACC ] STREAM LISTENING 23118 private/anvil
unix 2 [ ACC ] STREAM LISTENING 23121 private/scache
unix 2 [ ACC ] STREAM LISTENING 21572 /var/run/NetworkManager/private-dhcp
unix 2 [ ACC ] STREAM LISTENING 23073 private/defer
unix 2 [ ACC ] STREAM LISTENING 23076 private/trace
unix 2 [ ACC ] STREAM LISTENING 23079 private/verify
unix 2 [ ACC ] STREAM LISTENING 18768 /var/run/vmware/guestServicePipe
unix 2 [ ACC ] STREAM LISTENING 18605 /var/run/abrt/abrt.socket
unix 2 [ ACC ] STREAM LISTENING 23057 public/cleanup
unix 2 [ ACC ] STREAM LISTENING 23060 public/qmgr
unix 2 [ ACC ] STREAM LISTENING 23082 public/flush
unix 2 [ ACC ] STREAM LISTENING 23097 public/showq
unix 2 [ ACC ] STREAM LISTENING 23053 public/pickup
unix 2 [ ACC ] STREAM LISTENING 13274 /run/systemd/private
unix 2 [ ACC ] STREAM LISTENING 17889 /run/dbus/system_bus_socket
unix 2 [ ACC ] SEQPACKET LISTENING 13291 /run/udev/control
unix 2 [ ] DGRAM 13539 /run/systemd/shutdownd
unix 3 [ ] STREAM CONNECTED 18502
unix 3 [ ] STREAM CONNECTED 23114
unix 3 [ ] STREAM CONNECTED 23059
unix 2 [ ] DGRAM 18564
unix 2 [ ] DGRAM 32827
unix 3 [ ] STREAM CONNECTED 23122
unix 3 [ ] STREAM CONNECTED 23075
unix 3 [ ] STREAM CONNECTED 23061
unix 3 [ ] STREAM CONNECTED 23055
unix 3 [ ] STREAM CONNECTED 19700 /run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 17469
unix 3 [ ] STREAM CONNECTED 23101
unix 3 [ ] DGRAM 14191
unix 3 [ ] STREAM CONNECTED 18533
unix 3 [ ] STREAM CONNECTED 23089
unix 2 [ ] DGRAM 20790
unix 3 [ ] STREAM CONNECTED 23083
unix 3 [ ] STREAM CONNECTED 23068
unix 2 [ ] DGRAM 18607
unix 3 [ ] STREAM CONNECTED 18004 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 23110
unix 3 [ ] STREAM CONNECTED 23051
unix 3 [ ] STREAM CONNECTED 23093
unix 3 [ ] STREAM CONNECTED 23087
unix 3 [ ] STREAM CONNECTED 23072
unix 3 [ ] STREAM CONNECTED 18499 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 19049
unix 3 [ ] STREAM CONNECTED 18580
unix 2 [ ] DGRAM 22531
unix 3 [ ] STREAM CONNECTED 23113
unix 3 [ ] STREAM CONNECTED 23098
unix 3 [ ] STREAM CONNECTED 22153
unix 2 [ ] DGRAM 23150
unix 3 [ ] STREAM CONNECTED 23080
unix 3 [ ] STREAM CONNECTED 18445
unix 2 [ ] DGRAM 19902
unix 3 [ ] STREAM CONNECTED 18572
unix 3 [ ] DGRAM 14190
unix 2 [ ] DGRAM 13642
unix 3 [ ] STREAM CONNECTED 23117
unix 3 [ ] STREAM CONNECTED 23102
unix 3 [ ] STREAM CONNECTED 23084
unix 3 [ ] STREAM CONNECTED 23228 /run/dbus/system_bus_socket
unix 2 [ ] DGRAM 14172
unix 3 [ ] STREAM CONNECTED 23105
unix 3 [ ] STREAM CONNECTED 23090
unix 2 [ ] DGRAM 17459
unix 3 [ ] STREAM CONNECTED 19699
unix 3 [ ] STREAM CONNECTED 14167 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 23071
unix 3 [ ] STREAM CONNECTED 18402
unix 3 [ ] STREAM CONNECTED 23099
unix 3 [ ] STREAM CONNECTED 18995 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 23077
unix 3 [ ] STREAM CONNECTED 23052
unix 3 [ ] STREAM CONNECTED 18581
unix 3 [ ] STREAM CONNECTED 18103
unix 3 [ ] STREAM CONNECTED 18003
unix 3 [ ] STREAM CONNECTED 23120
unix 3 [ ] STREAM CONNECTED 23081
unix 3 [ ] STREAM CONNECTED 23066
unix 3 [ ] STREAM CONNECTED 18498
unix 3 [ ] STREAM CONNECTED 23116
unix 3 [ ] STREAM CONNECTED 19760 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 23058
unix 3 [ ] STREAM CONNECTED 20931 /run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 20930
unix 3 [ ] STREAM CONNECTED 19832 /run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 18586 /run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 18582 /run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 23227
unix 3 [ ] STREAM CONNECTED 23095
unix 3 [ ] STREAM CONNECTED 23074
unix 3 [ ] STREAM CONNECTED 23108
unix 3 [ ] STREAM CONNECTED 22154 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 19790
unix 3 [ ] STREAM CONNECTED 18403 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 23062
unix 3 [ ] STREAM CONNECTED 23054
unix 3 [ ] STREAM CONNECTED 23119
unix 3 [ ] STREAM CONNECTED 18446 /run/systemd/journal/stdout
unix 2 [ ] DGRAM 19021
unix 3 [ ] STREAM CONNECTED 14166
unix 3 [ ] STREAM CONNECTED 23065
unix 2 [ ] DGRAM 23026
unix 3 [ ] STREAM CONNECTED 17468
unix 3 [ ] STREAM CONNECTED 23104
unix 3 [ ] STREAM CONNECTED 23123
unix 3 [ ] STREAM CONNECTED 23078
unix 2 [ ] DGRAM 18522
unix 3 [ ] STREAM CONNECTED 18994
unix 3 [ ] STREAM CONNECTED 18587 /run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 18104 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 23069
unix 3 [ ] STREAM CONNECTED 23107
unix 3 [ ] STREAM CONNECTED 23092
unix 3 [ ] STREAM CONNECTED 22216
unix 2 [ ] DGRAM 23443
unix 3 [ ] STREAM CONNECTED 19831
unix 2 [ ] DGRAM 13685
unix 3 [ ] STREAM CONNECTED 23111
unix 3 [ ] STREAM CONNECTED 23096
unix 3 [ ] STREAM CONNECTED 23086
unix 3 [ ] STREAM CONNECTED 22217 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 19759
表10-7 针对该命令的第一行内容进行了说明。
表10-7 第一行活动网络连接说明
表10-8针对该命令的第6列内容进行了说明。
表10-8 第6列State状态信息详解
**范例10-26:**常用选项组合(二)
[root@centos7 ~]# netstat -lntup
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:22 0.0.0.0:* LISTEN 1368/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1544/master
tcp6 0 0 :::22 :::* LISTEN 1368/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1544/master
以上命令语句的作用为显示所有TCP和UDP正在监听的连接信息。
**范例10-27:**显示当前系统的路由表。
[root@centos7 ~]# netstat -rn #使用-r选项显示路由表信息,-n选项不进行DNS解析,加快命令执行速度。
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.0.0.254 0.0.0.0 UG 0 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
172.16.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
#提示:该命令相当于route -n。
**范例10-28:**选项-i显示网络的接口状况。
[root@centos7 ~]# netstat -i
Kernel Interface table
Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0 1500 2688 0 0 0 1871 0 0 0 BMRU
eth1 1500 55 0 0 0 31 0 0 0 BMRU
eth1:1 1500 - no statistics available - BMRU
lo 65536 0 0 0 0 0 0 0 0 LRU
以下是命令结果解释。
正常情况下,RX-ERR/TX-ERR、RX-DRP/TX-DRP 和RX-OVR/TX-OVR的值都应该为0,如果这几个选项的值不为0,并且很大,那么网络质量肯定有问题,网络传输性能也一定会下降。
**范例10-29:**统计各个状态的网络连接个数。
[root@centos7 ~]# netstat -n |awk '/^tcp/ {++neteagle[$NF]} END {for(a in neteagle) print a,neteagle[a]}' #这个范例利用了awk数组的功能,awk的使用请参考本书第4张。
ESTABLISHED 1
【命令星级】 ★★★★★
【功能说明】
ss命令是类似并将取代netstat的工具,它能用来查看网络状态信息,包括TCP、UDP连接、端口等。它的优点是能够显示更多更详细的有关网络连接状态的信息,而且比netstat更快速更高效。
如果系统没有ss命令,拿就需要安装一下,ss命令属于iproute包,因此安装命令是yum -y install iproute。
【语法格式】
ss [option] [filter]
ss [选项] [过滤器]
**说明:**在ss命令及后面的选项和过滤器里,每个元素直接都至少要有一个空格。
【选项说明】
表10-9针对该命令的参数选项进行了说明。
表10-9 ss命令的参数选项及说明
**范例10-30:**常用选项组合(一)。
[root@centos7 ~]# ss -an #显示所有的socket连接。
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
nl UNCONN 0 0 0:1014 *
nl UNCONN 0 0 0:0 *
nl UNCONN 0 0 0:1014 *
nl UNCONN 768 0 4:0 *
nl UNCONN 4352 0 4:2588 *
nl UNCONN 0 0 6:0 *
nl UNCONN 0 0 7:1 *
nl UNCONN 0 0 7:0 *
nl UNCONN 0 0 7:847 *
nl UNCONN 0 0 7:847 *
nl UNCONN 0 0 7:1 *
nl UNCONN 0 0 9:766 *
nl UNCONN 0 0 9:1 *
nl UNCONN 0 0 9:0 *
nl UNCONN 0 0 10:0 *
nl UNCONN 0 0 11:0 *
nl UNCONN 0 0 12:0 *
nl UNCONN 0 0 15:1369 *
nl UNCONN 0 0 15:0 *
nl UNCONN 0 0 15:400 *
nl UNCONN 0 0 15:1 *
nl UNCONN 0 0 15:-4117 *
nl UNCONN 0 0 15:-4120 *
nl UNCONN 0 0 15:-4107 *
nl UNCONN 0 0 15:1014 *
nl UNCONN 0 0 15:-4118 *
nl UNCONN 0 0 15:-4119 *
nl UNCONN 0 0 15:843 *
nl UNCONN 0 0 15:1369 *
nl UNCONN 0 0 15:-4120 *
nl UNCONN 0 0 15:1014 *
nl UNCONN 0 0 15:-4119 *
nl UNCONN 0 0 15:-4118 *
nl UNCONN 0 0 15:-4117 *
nl UNCONN 0 0 15:843 *
nl UNCONN 0 0 15:-4107 *
nl UNCONN 0 0 15:1 *
nl UNCONN 0 0 16:0 *
nl UNCONN 0 0 16:1014 *
nl UNCONN 0 0 18:0 *
p_dgr UNCONN 0 0 arp:eth0 *
u_str ESTAB 52 0 @001c4 40035 * 40036
u_dgr UNCONN 0 0 /run/systemd/notify 8965 * 0
u_dgr UNCONN 0 0 /run/systemd/cgroups-agent 8967 * 0
u_str LISTEN 0 100 private/tlsmgr 23064 * 0
u_str LISTEN 0 100 private/rewrite 23067 * 0
u_str LISTEN 0 100 private/bounce 23070 * 0
u_str LISTEN 0 100 private/proxymap 23085 * 0
u_str LISTEN 0 128 /run/systemd/journal/stdout 8985 * 0
u_str LISTEN 0 100 private/proxywrite 23088 * 0
u_str LISTEN 0 100 private/smtp 23091 * 0
u_dgr UNCONN 0 0 /run/systemd/journal/socket 8988 * 0
u_str LISTEN 0 100 private/relay 23094 * 0
u_str LISTEN 0 100 private/error 23100 * 0
u_dgr UNCONN 0 0 /dev/log 8990 * 0
u_str LISTEN 0 100 private/retry 23103 * 0
u_str LISTEN 0 100 private/discard 23106 * 0
u_str LISTEN 0 100 private/local 23109 * 0
u_str LISTEN 0 100 private/virtual 23112 * 0
u_str LISTEN 0 100 private/lmtp 23115 * 0
u_str LISTEN 0 100 private/anvil 23118 * 0
u_str LISTEN 0 100 private/scache 23121 * 0
u_str LISTEN 0 10 /var/run/NetworkManager/private-dhcp 21572 * 0
u_str LISTEN 0 100 private/defer 23073 * 0
u_str LISTEN 0 100 private/trace 23076 * 0
u_str LISTEN 0 100 private/verify 23079 * 0
u_str LISTEN 0 32 /var/run/vmware/guestServicePipe 18768 * 0
u_str LISTEN 0 10 /var/run/abrt/abrt.socket 18605 * 0
u_str LISTEN 0 100 public/cleanup 23057 * 0
u_str LISTEN 0 100 public/qmgr 23060 * 0
u_str LISTEN 0 100 public/flush 23082 * 0
u_str LISTEN 0 100 public/showq 23097 * 0
u_str LISTEN 0 100 public/pickup 23053 * 0
u_str LISTEN 0 128 /run/systemd/private 13274 * 0
u_str LISTEN 0 128 /run/dbus/system_bus_socket 17889 * 0
u_seq LISTEN 0 128 /run/udev/control 13291 * 0
u_dgr UNCONN 0 0 /run/systemd/shutdownd 13539 * 0
u_str ESTAB 0 0 * 18502 * 18582
u_str ESTAB 0 0 * 23114 * 23113
u_str ESTAB 0 0 * 23059 * 23058
u_dgr UNCONN 0 0 * 18564 * 0
u_dgr UNCONN 0 0 * 32827 * 8990
u_str ESTAB 0 0 * 23122 * 23123
u_str ESTAB 0 0 * 23075 * 23074
u_str ESTAB 0 0 * 23061 * 23062
u_str ESTAB 0 0 * 23055 * 23054
u_str ESTAB 0 0 /run/dbus/system_bus_socket 19700 * 19699
u_str ESTAB 0 0 * 17469 * 17468
u_str ESTAB 0 0 * 23101 * 23102
u_dgr UNCONN 0 0 * 14191 * 14190
u_str ESTAB 0 0 * 18533 * 18586
u_str ESTAB 0 0 * 23089 * 23090
u_dgr UNCONN 0 0 * 20790 * 8990
u_str ESTAB 0 0 * 23083 * 23084
u_str ESTAB 0 0 * 23068 * 23069
u_dgr UNCONN 0 0 * 18607 * 0
u_str ESTAB 0 0 /run/systemd/journal/stdout 18004 * 18003
u_str ESTAB 0 0 * 23110 * 23111
u_str ESTAB 0 0 * 23051 * 23052
u_str ESTAB 0 0 * 23093 * 23092
u_str ESTAB 0 0 * 23087 * 23086
u_str ESTAB 0 0 * 23072 * 23071
u_str ESTAB 0 0 /run/systemd/journal/stdout 18499 * 18498
u_dgr UNCONN 0 0 * 19049 * 8990
u_str ESTAB 0 0 * 18580 * 18581
u_dgr UNCONN 0 0 * 22531 * 8990
u_str ESTAB 0 0 * 23113 * 23114
u_str ESTAB 0 0 * 23098 * 23099
u_str ESTAB 0 0 * 22153 * 22154
u_dgr UNCONN 0 0 * 23150 * 8990
u_str ESTAB 0 0 * 23080 * 23081
u_str ESTAB 0 0 * 18445 * 18446
u_dgr UNCONN 0 0 * 19902 * 8990
u_str ESTAB 0 0 * 18572 * 18587
u_dgr UNCONN 0 0 * 14190 * 14191
u_dgr UNCONN 0 0 * 13642 * 8965
u_str ESTAB 0 0 * 23117 * 23116
u_str ESTAB 0 0 * 23102 * 23101
u_str ESTAB 0 0 * 23084 * 23083
u_str ESTAB 0 0 /run/dbus/system_bus_socket 23228 * 23227
u_dgr UNCONN 0 0 * 14172 * 8988
u_str ESTAB 0 0 * 23105 * 23104
u_str ESTAB 0 0 * 23090 * 23089
u_dgr UNCONN 0 0 * 17459 * 8990
u_str ESTAB 0 0 * 19699 * 19700
u_str ESTAB 0 0 /run/systemd/journal/stdout 14167 * 14166
u_str ESTAB 0 0 * 23071 * 23072
u_str ESTAB 0 0 * 18402 * 18403
u_str ESTAB 0 0 * 23099 * 23098
u_str ESTAB 0 0 /run/systemd/journal/stdout 18995 * 18994
u_str ESTAB 0 0 * 23077 * 23078
u_str ESTAB 0 0 * 23052 * 23051
u_str ESTAB 0 0 * 18581 * 18580
u_str ESTAB 0 0 * 18103 * 18104
u_str ESTAB 0 0 * 18003 * 18004
u_str ESTAB 0 0 * 23120 * 23119
u_str ESTAB 0 0 * 23081 * 23080
u_str ESTAB 0 0 * 23066 * 23065
u_str ESTAB 0 0 * 18498 * 18499
u_str ESTAB 0 0 * 23116 * 23117
u_str ESTAB 0 0 /run/systemd/journal/stdout 19760 * 19759
u_str ESTAB 0 0 * 23058 * 23059
u_str ESTAB 0 0 /run/dbus/system_bus_socket 20931 * 20930
u_str ESTAB 0 0 * 20930 * 20931
u_str ESTAB 0 0 /run/dbus/system_bus_socket 19832 * 19831
u_str ESTAB 0 0 /run/dbus/system_bus_socket 18586 * 18533
u_str ESTAB 0 0 /run/dbus/system_bus_socket 18582 * 18502
u_str ESTAB 0 0 * 23227 * 23228
u_str ESTAB 0 0 * 23095 * 23096
u_str ESTAB 0 0 * 23074 * 23075
u_str ESTAB 0 0 * 23108 * 23107
u_str ESTAB 0 0 /run/systemd/journal/stdout 22154 * 22153
u_dgr UNCONN 0 0 * 19790 * 8990
u_str ESTAB 0 0 /run/systemd/journal/stdout 18403 * 18402
u_str ESTAB 0 0 * 23062 * 23061
u_str ESTAB 0 768 /run/systemd/private 40036 * 40035
u_str ESTAB 0 0 * 23054 * 23055
u_str ESTAB 0 0 * 23119 * 23120
u_str ESTAB 0 0 /run/systemd/journal/stdout 18446 * 18445
u_dgr UNCONN 0 0 * 19021 * 8990
u_str ESTAB 0 0 * 14166 * 14167
u_str ESTAB 0 0 * 23065 * 23066
u_dgr UNCONN 0 0 * 23026 * 8990
u_str ESTAB 0 0 * 17468 * 17469
u_str ESTAB 0 0 * 23104 * 23105
u_str ESTAB 0 0 * 23123 * 23122
u_str ESTAB 0 0 * 23078 * 23077
u_dgr UNCONN 0 0 * 18522 * 8988
u_str ESTAB 0 0 * 18994 * 18995
u_str ESTAB 0 0 /run/dbus/system_bus_socket 18587 * 18572
u_str ESTAB 0 0 /run/systemd/journal/stdout 18104 * 18103
u_str ESTAB 0 0 * 23069 * 23068
u_str ESTAB 0 0 * 23107 * 23108
u_str ESTAB 0 0 * 23092 * 23093
u_str ESTAB 0 0 * 22216 * 22217
u_dgr UNCONN 0 0 * 23443 * 8990
u_str ESTAB 0 0 * 19831 * 19832
u_dgr UNCONN 0 0 * 13685 * 8988
u_str ESTAB 0 0 * 23111 * 23110
u_str ESTAB 0 0 * 23096 * 23095
u_str ESTAB 0 0 * 23086 * 23087
u_str ESTAB 0 0 /run/systemd/journal/stdout 22217 * 22216
u_str ESTAB 0 0 * 19759 * 19760
raw UNCONN 0 0 [::]:58 [::]:*
tcp LISTEN 0 128 *:22 *:*
tcp LISTEN 0 100 127.0.0.1:25 *:*
tcp ESTAB 0 148 10.0.0.201:22 10.0.0.1:61194
tcp LISTEN 0 128 [::]:22 [::]:*
tcp LISTEN 0 100 [::1]:25 [::]:*
v_str ESTAB 0 0 2251463184:1023 0:976
[root@centos7 ~]# ss -an |column -t #上面的输出写在文档中会有点乱,下面用column格式化一下。
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
nl UNCONN 0 0 0:1014 *
nl UNCONN 0 0 0:0 *
nl UNCONN 0 0 0:1014 *
nl UNCONN 4352 0 4:2825 *
nl UNCONN 768 0 4:0 *
nl UNCONN 0 0 6:0 *
nl UNCONN 0 0 7:1 *
nl UNCONN 0 0 7:0 *
nl UNCONN 0 0 7:847 *
nl UNCONN 0 0 7:847 *
nl UNCONN 0 0 7:1 *
nl UNCONN 0 0 9:766 *
nl UNCONN 0 0 9:1 *
nl UNCONN 0 0 9:0 *
nl UNCONN 0 0 10:0 *
nl UNCONN 0 0 11:0 *
nl UNCONN 0 0 12:0 *
nl UNCONN 0 0 15:1369 *
nl UNCONN 0 0 15:0 *
nl UNCONN 0 0 15:1 *
nl UNCONN 0 0 15:-4117 *
nl UNCONN 0 0 15:-4120 *
nl UNCONN 0 0 15:-4107 *
nl UNCONN 0 0 15:1014 *
nl UNCONN 0 0 15:-4118 *
nl UNCONN 0 0 15:-4119 *
nl UNCONN 0 0 15:843 *
nl UNCONN 0 0 15:1369 *
nl UNCONN 0 0 15:-4120 *
nl UNCONN 0 0 15:1014 *
nl UNCONN 0 0 15:-4119 *
nl UNCONN 0 0 15:-4118 *
nl UNCONN 0 0 15:-4117 *
nl UNCONN 0 0 15:843 *
nl UNCONN 0 0 15:-4107 *
nl UNCONN 0 0 15:1 *
nl UNCONN 0 0 16:0 *
nl UNCONN 0 0 16:1014 *
nl UNCONN 0 0 18:0 *
p_dgr UNCONN 0 0 arp:eth0 *
u_dgr UNCONN 0 0 /run/systemd/notify 8965 * 0
u_dgr UNCONN 0 0 /run/systemd/cgroups-agent 8967 * 0
u_str LISTEN 0 100 private/tlsmgr 23064 * 0
u_str LISTEN 0 100 private/rewrite 23067 * 0
u_str LISTEN 0 100 private/bounce 23070 * 0
u_str LISTEN 0 100 private/proxymap 23085 * 0
u_str LISTEN 0 128 /run/systemd/journal/stdout 8985 * 0
u_str LISTEN 0 100 private/proxywrite 23088 * 0
u_str LISTEN 0 100 private/smtp 23091 * 0
u_dgr UNCONN 0 0 /run/systemd/journal/socket 8988 * 0
u_str LISTEN 0 100 private/relay 23094 * 0
u_str LISTEN 0 100 private/error 23100 * 0
u_dgr UNCONN 0 0 /dev/log 8990 * 0
u_str LISTEN 0 100 private/retry 23103 * 0
u_str LISTEN 0 100 private/discard 23106 * 0
u_str LISTEN 0 100 private/local 23109 * 0
u_str LISTEN 0 100 private/virtual 23112 * 0
u_str LISTEN 0 100 private/lmtp 23115 * 0
u_str LISTEN 0 100 private/anvil 23118 * 0
u_str LISTEN 0 100 private/scache 23121 * 0
u_str LISTEN 0 10 /var/run/NetworkManager/private-dhcp 21572 * 0
u_str LISTEN 0 100 private/defer 23073 * 0
u_str LISTEN 0 100 private/trace 23076 * 0
u_str LISTEN 0 100 private/verify 23079 * 0
u_str LISTEN 0 32 /var/run/vmware/guestServicePipe 18768 * 0
u_str LISTEN 0 10 /var/run/abrt/abrt.socket 18605 * 0
u_str LISTEN 0 100 public/cleanup 23057 * 0
u_str LISTEN 0 100 public/qmgr 23060 * 0
u_str LISTEN 0 100 public/flush 23082 * 0
u_str LISTEN 0 100 public/showq 23097 * 0
u_str LISTEN 0 100 public/pickup 23053 * 0
u_str LISTEN 0 128 /run/systemd/private 13274 * 0
u_str LISTEN 0 128 /run/dbus/system_bus_socket 17889 * 0
u_seq LISTEN 0 128 /run/udev/control 13291 * 0
u_dgr UNCONN 0 0 /run/systemd/shutdownd 13539 * 0
u_str ESTAB 0 0 * 18502 * 18582
u_str ESTAB 0 0 * 23114 * 23113
u_str ESTAB 0 0 * 23059 * 23058
u_dgr UNCONN 0 0 * 18564 * 0
u_dgr UNCONN 0 0 * 32827 * 8990
u_str ESTAB 0 0 * 23122 * 23123
u_str ESTAB 0 0 * 23075 * 23074
u_str ESTAB 0 0 * 23061 * 23062
u_str ESTAB 0 0 * 23055 * 23054
u_str ESTAB 0 0 /run/dbus/system_bus_socket 19700 * 19699
u_str ESTAB 0 0 * 17469 * 17468
u_str ESTAB 0 0 * 23101 * 23102
u_dgr UNCONN 0 0 * 14191 * 14190
u_str ESTAB 0 0 * 18533 * 18586
u_str ESTAB 0 0 * 23089 * 23090
u_dgr UNCONN 0 0 * 20790 * 8990
u_str ESTAB 0 0 * 23083 * 23084
u_str ESTAB 0 0 * 23068 * 23069
u_dgr UNCONN 0 0 * 18607 * 0
u_str ESTAB 0 0 /run/systemd/journal/stdout 18004 * 18003
u_str ESTAB 0 0 * 23110 * 23111
u_str ESTAB 0 0 * 23051 * 23052
u_str ESTAB 0 0 * 23093 * 23092
u_str ESTAB 0 0 * 23087 * 23086
u_str ESTAB 0 0 * 23072 * 23071
u_str ESTAB 0 0 /run/systemd/journal/stdout 18499 * 18498
u_dgr UNCONN 0 0 * 19049 * 8990
u_str ESTAB 0 0 * 18580 * 18581
u_dgr UNCONN 0 0 * 22531 * 8990
u_str ESTAB 0 0 * 23113 * 23114
u_str ESTAB 0 0 * 23098 * 23099
u_str ESTAB 0 0 * 22153 * 22154
u_dgr UNCONN 0 0 * 23150 * 8990
u_str ESTAB 0 0 * 23080 * 23081
u_str ESTAB 0 0 * 18445 * 18446
u_dgr UNCONN 0 0 * 19902 * 8990
u_str ESTAB 0 0 * 18572 * 18587
u_dgr UNCONN 0 0 * 14190 * 14191
u_dgr UNCONN 0 0 * 13642 * 8965
u_str ESTAB 0 0 * 23117 * 23116
u_str ESTAB 0 0 * 23102 * 23101
u_str ESTAB 0 0 * 23084 * 23083
u_str ESTAB 0 0 /run/dbus/system_bus_socket 23228 * 23227
u_dgr UNCONN 0 0 * 14172 * 8988
u_str ESTAB 0 0 * 23105 * 23104
u_str ESTAB 0 0 * 23090 * 23089
u_dgr UNCONN 0 0 * 17459 * 8990
u_str ESTAB 0 0 * 19699 * 19700
u_str ESTAB 0 0 /run/systemd/journal/stdout 14167 * 14166
u_str ESTAB 0 0 * 23071 * 23072
u_str ESTAB 0 0 * 18402 * 18403
u_str ESTAB 0 0 * 23099 * 23098
u_str ESTAB 0 0 /run/systemd/journal/stdout 18995 * 18994
u_str ESTAB 0 0 * 23077 * 23078
u_str ESTAB 0 0 * 23052 * 23051
u_str ESTAB 0 0 * 18581 * 18580
u_str ESTAB 0 0 * 18103 * 18104
u_str ESTAB 0 0 * 18003 * 18004
u_str ESTAB 0 0 * 23120 * 23119
u_str ESTAB 0 0 * 23081 * 23080
u_str ESTAB 0 0 * 23066 * 23065
u_str ESTAB 0 0 * 18498 * 18499
u_str ESTAB 0 0 * 23116 * 23117
u_str ESTAB 0 0 /run/systemd/journal/stdout 19760 * 19759
u_str ESTAB 0 0 * 23058 * 23059
u_str ESTAB 0 0 /run/dbus/system_bus_socket 20931 * 20930
u_str ESTAB 0 0 * 20930 * 20931
u_str ESTAB 0 0 /run/dbus/system_bus_socket 19832 * 19831
u_str ESTAB 0 0 /run/dbus/system_bus_socket 18586 * 18533
u_str ESTAB 0 0 /run/dbus/system_bus_socket 18582 * 18502
u_str ESTAB 0 0 * 23227 * 23228
u_str ESTAB 0 0 * 23095 * 23096
u_str ESTAB 0 0 * 23074 * 23075
u_str ESTAB 0 0 * 23108 * 23107
u_str ESTAB 0 0 /run/systemd/journal/stdout 22154 * 22153
u_dgr UNCONN 0 0 * 19790 * 8990
u_str ESTAB 0 0 /run/systemd/journal/stdout 18403 * 18402
u_str ESTAB 0 0 * 23062 * 23061
u_str ESTAB 0 0 * 23054 * 23055
u_str ESTAB 0 0 * 23119 * 23120
u_str ESTAB 0 0 /run/systemd/journal/stdout 18446 * 18445
u_dgr UNCONN 0 0 * 19021 * 8990
u_str ESTAB 0 0 * 14166 * 14167
u_str ESTAB 0 0 * 23065 * 23066
u_dgr UNCONN 0 0 * 23026 * 8990
u_str ESTAB 0 0 * 17468 * 17469
u_str ESTAB 0 0 * 23104 * 23105
u_str ESTAB 0 0 * 23123 * 23122
u_str ESTAB 0 0 * 23078 * 23077
u_dgr UNCONN 0 0 * 18522 * 8988
u_str ESTAB 0 0 * 18994 * 18995
u_str ESTAB 0 0 /run/dbus/system_bus_socket 18587 * 18572
u_str ESTAB 0 0 /run/systemd/journal/stdout 18104 * 18103
u_str ESTAB 0 0 * 23069 * 23068
u_str ESTAB 0 0 * 23107 * 23108
u_str ESTAB 0 0 * 23092 * 23093
u_str ESTAB 0 0 * 22216 * 22217
u_dgr UNCONN 0 0 * 23443 * 8990
u_str ESTAB 0 0 * 19831 * 19832
u_dgr UNCONN 0 0 * 13685 * 8988
u_str ESTAB 0 0 * 23111 * 23110
u_str ESTAB 0 0 * 23096 * 23095
u_str ESTAB 0 0 * 23086 * 23087
u_str ESTAB 0 0 /run/systemd/journal/stdout 22217 * 22216
u_str ESTAB 0 0 * 19759 * 19760
raw UNCONN 0 0 [::]:58 [::]:*
tcp LISTEN 0 128 *:22 *:*
tcp LISTEN 0 100 127.0.0.1:25 *:*
tcp ESTAB 0 52 10.0.0.201:22 10.0.0.1:61194
tcp LISTEN 0 128 [::]:22 [::]:*
tcp LISTEN 0 100 [::1]:25 [::]:*
v_str ESTAB 0 0 2251463184:1023 0:976
**范例10-31:**常用选项组合(二)。
[root@centos7 ~]# ss -lntup |column -t #显示所有正在监听的TCP和UDP连接。
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp LISTEN 0 128 *:22 *:* users:(("sshd",pid=1368,fd=3))
tcp LISTEN 0 100 127.0.0.1:25 *:* users:(("master",pid=1544,fd=13))
tcp LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=1368,fd=4))
tcp LISTEN 0 100 [::1]:25 [::]:* users:(("master",pid=1544,fd=14))
**范例10-32:**显示socket统计。
[root@centos7 ~]# ss -s #统计当前的established、closed、orphaned、waiting的TCP socket数量。
Total: 564 (kernel 1020)
TCP: 5 (estab 1, closed 0, orphaned 0, synrecv 0, timewait 0/0), ports 0
Transport Total IP IPv6
* 1020 - -
RAW 1 0 1
UDP 0 0 0
TCP 5 3 2
INET 6 3 3
FRAG 0 0 0
当服务器产生大量的socket连接时,通常会使用该命令来做宏观数据统计;ss的大部分参数应用和netstat很像,读者可以参考netstat相关参数的用法。