Linux 网络状态工具 ss,代替 netstat
Linux ss 诊断工具 大约 7154 字说明
ss
是Socket Statistics
的缩写,是iproute
工具集中的一员。
天下武功唯快不破。ss 快的秘诀在于,它利用到了 TCP 协议栈中 tcp_diag。tcp_diag 是一个用于分析统计的模块,可以获得 Linux 内核中第一手的信息,这就确保了 ss 的快捷高效。当然,如果你的系统中没有 tcp_diag,ss 也可以正常运行,只是效率会变得稍慢。(但仍然比 netstat 要快。)
查看是否安装
rpm -qf /usr/sbin/ss
或:
rpm -q iproute
输出:
iproute-2.6.32-45.el6.x86_64
安装
如果无法使用ss
命令,需安装iproute
,一般现在Linux
系统默认安装了iproute
,故可以直接使用ss
。
yum install iproute iproute-doc
iproute 与 net-tool 对比
用途 | net-tool | iproute2 |
---|---|---|
地址和链路配置 | ifconfig | ip addr, ip link |
路由表 | route | ip route |
邻居 | arp | ip neigh |
VLAN | vconfig | ip link |
隧道 | iptunnel | ip tunnel |
组播 | ipmaddr | ip maddr |
统计 | netstat | ss |
ss 命令
帮助文档
ss -h
获取 ss 版本号
ss -V
查看当前服务器的网络连接统计
ss -s
输出:
[root@root ~]$ ss -s
Total: 953 (kernel 1080)
TCP: 754 (estab 722, closed 4, orphaned 0, synrecv 0, timewait 0/0), ports 775
Transport Total IP IPv6
* 1080 - -
RAW 0 0 0
UDP 21 21 0
TCP 750 750 0
INET 771 771 0
FRAG 0 0 0
查看所有打开的网络端口
- 使用
-l
参数。
ss -l
输出:
[root@root ~]$ ss -l
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:rquotad *:*
LISTEN 0 100 *:8109 *:*
LISTEN 0 128 *:sunrpc *:*
LISTEN 0 50 *:20880 *:*
LISTEN 0 50 *:20881 *:*
LISTEN 0 50 *:20882 *:*
LISTEN 0 50 *:20883 *:*
LISTEN 0 1 127.0.0.1:18005 *:*
LISTEN 0 50 *:20885 *:*
LISTEN 0 128 *:44565 *:*
LISTEN 0 128 *:ssh *:*
LISTEN 0 128 127.0.0.1:ipp *:*
LISTEN 0 50 *:16377 *:*
LISTEN 0 500 *:8090 *:*
LISTEN 0 64 *:64156 *:*
LISTEN 0 128 *:59231 *:*
LISTEN 0 50 *:24384 *:*
LISTEN 0 64 *:2049 *:*
LISTEN 0 128 *:9090 *:*
LISTEN 0 128 *:35107 *:*
LISTEN 0 1 127.0.0.1:8006 *:*
LISTEN 0 500 *:7080 *:*
LISTEN 0 100 *:8009 *:*
LISTEN 0 50 *:2346 *:*
LISTEN 0 900 *:3306 *:*
- 使用
-pl
参数,显示具体进程名称,类似:("nginx",1673,6)
ss -pl
输出:
[root@root ~]$ ss -pl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:rquotad *:*
LISTEN 0 100 *:8109 *:* users:(("java",60344,55))
LISTEN 0 128 *:sunrpc *:*
LISTEN 0 50 *:20880 *:* users:(("java",60344,239))
LISTEN 0 50 *:20881 *:* users:(("java",15677,140))
LISTEN 0 50 *:20882 *:* users:(("java",17575,139))
LISTEN 0 50 *:20883 *:* users:(("java",28128,117))
LISTEN 0 1 127.0.0.1:18005 *:* users:(("java",60484,77))
LISTEN 0 50 *:20885 *:* users:(("java",60484,242))
LISTEN 0 128 *:44565 *:*
LISTEN 0 128 *:ssh *:*
LISTEN 0 128 127.0.0.1:ipp *:*
LISTEN 0 50 *:16377 *:* users:(("java",60484,19))
LISTEN 0 500 *:8090 *:* users:(("java",60484,54))
LISTEN 0 64 *:64156 *:*
LISTEN 0 128 *:59231 *:*
LISTEN 0 50 *:24384 *:* users:(("java",60484,21))
LISTEN 0 64 *:2049 *:*
LISTEN 0 128 *:9090 *:*
LISTEN 0 128 *:35107 *:*
LISTEN 0 1 127.0.0.1:8006 *:* users:(("java",60344,74))
LISTEN 0 500 *:7080 *:* users:(("java",60344,50))
LISTEN 0 100 *:8009 *:* users:(("java",60484,58))
LISTEN 0 50 *:2346 *:* users:(("java",60484,20))
LISTEN 0 900 *:3306 *:*
LISTEN 0 128 *:https *:* users:(("nginx",1673,6),("nginx",958,6))
LISTEN 0 128 :::http :::* users:(("nginx",1673,8),("nginx",958,8))
查看服务器上所有的 socket 连接
- 查看所有
socket
连接
ss -a
输出:
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 1 127.0.0.1:18005 *:*
LISTEN 0 50 *:20885 *:*
LISTEN 0 128 *:44565 *:*
LISTEN 0 1 127.0.0.1:8006 *:*
LISTEN 0 500 *:7080 *:*
LISTEN 0 900 *:3306 *:*
ESTAB 0 0 10.95.197.161:28892 10.95.216.9:7005
ESTAB 0 0 10.95.197.161:45596 10.95.216.116:7070
ESTAB 0 0 10.95.197.161:22437 10.95.216.10:7000
ESTAB 0 0 10.95.197.161:57115 10.95.216.9:7000
ESTAB 0 0 10.95.197.161:22185 10.95.216.10:7000
ESTAB 0 0 10.95.197.161:60830 10.95.216.10:7001
CLOSE-WAIT 61 0 10.95.197.161:12398 123.103.23.214:ftp
CLOSE-WAIT 61 0 10.95.197.161:54971 123.103.23.214:ftp
CLOSE-WAIT 61 0 10.95.197.161:56481 123.103.23.214:ftp
- 查看连接本机 22 端口
ss -n src :22
- 查看远程机器连接情况
ss -n dst 192.168.100.100
- 只查看 TCP sockets,tcp all
ss -ta
- 只查看 UDP sockets,udp all
ss -ua
- 只查看RAW sockets,raw all
ss -wa
- 只查看 UNIX sockets,unix all
ss -xa
阅读 14256 · 发布于 2019-09-04
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
HTTP Bad chunk header 和 Illegal or missing hexadecimal sequence in chunked-encoding 解决方法阅读 607
-
Windows C 盘隐藏文件 pagefile.sys 扩大电脑内存阅读 950
-
Spring 循环依赖:本地不报错,线上却报错阅读 379
-
Node.js 模块阅读 424
-
Linux 增加 Swap 交换分区解决内存不足阅读 2615
-
Maven 单元测试覆盖率检测插件 JaCoCo阅读 483
-
SQL Server 修改计算机名后修改服务名阅读 1774
-
Linux 查看系统负载阅读 86
-
PHP 序列化与反序列化阅读 2073
-
Go 关键字阅读 2106