当前位置:网站首页>监视网络连接的ss命令
监视网络连接的ss命令
2022-08-01 10:15:00 【yuyuyuliang00】
ss命令是一个用于在Linux系统上显示网络套接字相关信息的工具。这个工具显示比用于显示活动套接字连接的netstat命令更详细的信息。我们在这里专研并且看一下如何使用ss命令在Linux中显示变化的套接字连接信息。
1)列出所有连接
不带任何选项的基本ss命令只是列出所有连接,不管这些连接所在状态。
[[email protected] ~]$ ss
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
...
tcp ESTAB 0 48 172.28.133.248:ssh 61.87.239.94:54191
tcp ESTAB 0 0 172.28.133.248:38194 100.100.30.26:http
tcp ESTAB 0 0 172.28.133.248:ssh 61.87.239.94:54192
2) 列出监听和非监听端口
你可以使用-a选项获取一个监听和非监听端口的列表。
[[email protected] blctrl]# ss -a
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
...
tcp LISTEN 0 128 127.0.0.1:x11-ssh-offset 0.0.0.0:*
tcp LISTEN 0 128 0.0.0.0:sunrpc 0.0.0.0:*
tcp LISTEN 0 128 0.0.0.0:ssh 0.0.0.0:*
tcp ESTAB 0 64 172.28.133.248:ssh 61.87.239.94:54191
tcp TIME-WAIT 0 0 172.28.133.248:55206 100.100.36.108:https
tcp ESTAB 0 0 172.28.133.248:38194 100.100.30.26:http
tcp ESTAB 0 0 172.28.133.248:ssh 61.87.239.94:54192
tcp LISTEN 0 128 [::]:sunrpc [::]:*
tcp LISTEN 0 128 *:telnet *:*
3、列出监听套接字
要只显示监听套接字,使用-l标记。
[[email protected] blctrl]# ss -l
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
...
tcp LISTEN 0 128 0.0.0.0:ssh 0.0.0.0:*
tcp LISTEN 0 128 [::]:sunrpc [::]:*
tcp LISTEN 0 128 *:telnet *:*
4、列出所有TCP连接
要显示所有TCP连接,使用-t选项。
[[email protected] blctrl]# ss -t
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
ESTAB 0 48 172.28.133.248:ssh 61.87.239.94:54191
ESTAB 0 0 172.28.133.248:38194 100.100.30.26:http
ESTAB 0 0 172.28.133.248:ssh 61.87.239.94:541925、列出所有监听的TCP连接
要查看所有监听的TCP套接字,使用-lt选项。
[[email protected] blctrl]# ss -lt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:smt *:*
LISTEN 0 128 *:ssh *:*
LISTEN 0 100 [::1]:smtp [::]:*
LISTEN 0 128 [::]:ssh [::]:*
6、列出所有UDP连接
要查看所有UDP套接字连接,使用-ua选项。
[[email protected] blctrl]# ss -ua
State Recv-Q Send-Q Local Address:Port Peer Address:Port
UNCONN 0 0 127.0.0.1:323 *:*
UNCONN 0 0 [::1]:323 [::]:*
、7、列出所有监听的UDP连接
要查看监听的UDP连接,使用-lu选项。
[[email protected] blctrl]# ss -lu
State Recv-Q Send-Q Local Address:Port Peer Address:Port
UNCONN 0 0 127.0.0.1:323 *:*
UNCONN 0 0 [::1]:323 [::]:*8、显示套接字的PID(进程IDs)
要显示与套接字连接相关联的进程IDs,使用-p标记。
[[email protected] blctrl]# ss -p
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp ESTAB 0 0 192.168.3.2:ssh 192.168.3.50:63561 users:(("sshd",pid=1580,fd=3),("sshd",pid=1556,fd=3))
tcp ESTAB 0 0 192.168.3.2:ssh 192.168.3.50:60873 users:(("sshd",pid=1498,fd=3),("sshd",pid=1492,fd=3))
9、显示概要统计
要显示概要统计,使用-s选项。
[[email protected] blctrl]# ss -s
Total: 200 (kernel 240)
TCP: 8 (estab 4, closed 0, orphaned 0, synrecv 0, timewait 0/0), ports 0
Transport Total IP IPv6
* 240 - -
RAW 1 0 1
UDP 2 1 1
TCP 8 6 2
INET 11 7 4
FRAG 0 0 010、显示IPv4和IPv6套接字连接
如果你只看IPv4套接字,使用-4选项。如果只看IPv6套接字,使用-6选项。
[[email protected] blctrl]# ss -4
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp ESTAB 0 48 192.168.3.2:ssh 192.168.3.50:63560
tcp ESTAB 0 0 192.168.3.2:ssh 192.168.3.50:60874
tcp ESTAB 0 0 192.168.3.2:ssh 192.168.3.50:63561
tcp ESTAB 0 0 192.168.3.2:ssh 192.168.3.50:60873
[[email protected] blctrl]# ss -6
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port11、通过端口号过滤连接
ss命令也让你过滤套接字端口号或地址号。例如,要显示一个ssh的目标或源端口的所有套接字连接,运行以下命令。
[[email protected] blctrl]# ss -at '( dport = :22 or sport = :22 )'
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:ssh *:*
ESTAB 0 48 192.168.3.2:ssh 192.168.3.50:63560
ESTAB 0 0 192.168.3.2:ssh 192.168.3.50:60874
ESTAB 0 0 192.168.3.2:ssh 192.168.3.50:63561
ESTAB 0 0 192.168.3.2:ssh 192.168.3.50:60873
LISTEN 0 128 [::]:ssh [::]:*作为替换,你可以运行以下命令:
[[email protected] blctrl]# ss -at '( dport = :ssh or sport = :ssh )'12、检查ss命令的手册
要获取ss命令用法的更多详解,使用以下命令查看手册页。
[[email protected] blctrl]# man ss边栏推荐
- 招聘随想2022
- STM32入门开发 介绍IIC总线、读写AT24C02(EEPROM)(采用模拟时序)
- WPF 截图控件之绘制箭头(五)「仿微信」
- 深度学习 | MATLAB实现GRU门控循环单元gruLayer参数设定
- Basic configuration commands of cisco switches (what is the save command of Huawei switches)
- 分类预测 | MATLAB实现1-DCNN一维卷积神经网络分类预测
- 对于小应用来讲,使用哪款数据库比较好?
- WPF 截图控件之绘制箭头(五)「仿微信」
- ModelArts-based object detection YOLOv3 practice [play with HUAWEI CLOUD]
- Explain / Desc execution plan analysis
猜你喜欢

How to implement deep copy in js?

Qt supports HEIC/HEIF format images

Android Security and Protection Policy

一文说明白ECDSA spec256k1 spec256r1 EdDSA ed25519千丝万缕的关系

WPF 截图控件之绘制箭头(五)「仿微信」

CTFshow,命令执行:web31

What is a stepper motor?40 pictures to show you!

Custom Types - Enums, Unions

DBPack SQL Tracing 功能及数据加密功能详解

STM32 Personal Notes - Watchdog
随机推荐
世界第4疯狂的科学家,在103岁生日那天去世了
对于小应用来讲,使用哪款数据库比较好?
Mysql索引相关的知识复盘一
Custom Types - Enums, Unions
编码解码(btoa、encodeURIComponent、encodeURI、escape)
Change Servlet project to SSM project
rpm and yum
Comprehensive experiment BGP
50.【Application of dynamic two-dimensional array】
Drawing arrows of WPF screenshot control (5) "Imitation WeChat"
EasyRecovery热门免费数据检测修复软件
cisco交换机基本配置命令(华为交换机保存命令是什么)
retired paddling
机器学习 | MATLAB实现支持向量机回归RegressionSVM参数设定
7/31 训练日志
How to find out hidden computer software (how to clean up the computer software hidden)
Pve delete virtual machine "for a collection"
C language game - minesweeper
Introduction and application of heap memory (including examples)
slice、splice、split傻傻分不清