首页 > 代码库 > Linux命令(33):netstat命令-显示网络端口信息
Linux命令(33):netstat命令-显示网络端口信息
netstat命令
功能说明
netstat命令用来显示本机网络连接、运行端口和中由表等信息,用法如下:
netstat [选项] |
常用参数
选项 | 说明 |
-a | 显示本机所有连接和监听端口 |
-n | 以网络IP地址的形式显示当前建立的有效连接和端口 |
-r | 显示路由表信息 |
-s | 显示按协议的统计信息。默认情况下,将显示IP、IPV6、ICMP、ICMPv6、TCP、TCPv6、UDP和UDPv6的统计信息 |
-v | 显示当前的有效连接,与“-n”选项类似 |
-t | 显示所有的TCP协议连接情况 |
-u | 显示所有的UDP协议连接情况 |
-c<秒> | 后面跟的秒数,表示每隔几秒就刷新显示一次 |
-i | 显示自动配置接口的状态 |
-l | 仅显示连接状态为“LISTEN”的服务折网络状态 |
-p | 显示连接对应的PID与程序名 |
常用组合:-tan,-uan,-tnl,-unl,-tnlp,-tnlup
示例
-at 列出所有TCP端口
[root@c7 shell]# netstat -at Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:ms-sql-s 0.0.0.0:* LISTEN tcp 0 0 localhost:smtp 0.0.0.0:* LISTEN tcp 0 0 localhost:ms-sql-m 0.0.0.0:* LISTEN tcp 0 0 localhost:ms-sql-s localhost:44341 ESTABLISHED tcp 0 0 localhost:38468 localhost:ms-sql-s TIME_WAIT tcp 0 52 c7:ssh bogon:63580 ESTABLISHED tcp 0 0 localhost:44341 localhost:ms-sql-s ESTABLISHED tcp 0 0 c7:ssh bogon:57957 ESTABLISHED tcp6 0 0 [::]:ssh [::]:* LISTEN tcp6 0 0 localhost:smtp [::]:* LISTEN 使用n,以IP形式显示 [root@c7 shell]# netstat -nat Active Internet connections (servers and established) 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 0.0.0.0:1433 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:1434 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:1433 127.0.0.1:44341 ESTABLISHED tcp 0 52 192.168.2.117:22 192.168.2.107:63580 ESTABLISHED tcp 0 0 127.0.0.1:44341 127.0.0.1:1433 ESTABLISHED tcp 0 0 192.168.2.117:22 192.168.2.107:57957 ESTABLISHED tcp6 0 0 :::22 :::* LISTEN tcp6 0 0 ::1:25 :::* LISTEN |
tlnpu 显示当前系统中已经启动的网络连接和对应的端口信息
[root@c7 shell]# netstat -tnlup 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 1089/sshd tcp 0 0 0.0.0.0:1433 0.0.0.0:* LISTEN 2258/sqlservr tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2252/master tcp 0 0 127.0.0.1:1434 0.0.0.0:* LISTEN 2258/sqlservr tcp6 0 0 :::22 :::* LISTEN 1089/sshd tcp6 0 0 ::1:25 :::* LISTEN 2252/master 结合grep找出sqlservr当前的端口信息 [root@c7 shell]# netstat -tlnpu | grep sqlservr tcp 0 0 0.0.0.0:1433 0.0.0.0:* LISTEN 2258/sqlservr tcp 0 0 127.0.0.1:1434 0.0.0.0:* LISTEN 2258/sqlservr |
atunp 显示当前系统上外于连接状态的资源信息
[root@c7 shell]# netstat -atunp Active Internet connections (servers and established) 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 1089/sshd tcp 0 0 0.0.0.0:1433 0.0.0.0:* LISTEN 2258/sqlservr tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2252/master tcp 0 0 127.0.0.1:1434 0.0.0.0:* LISTEN 2258/sqlservr tcp 0 0 127.0.0.1:1433 127.0.0.1:44341 ESTABLISHED 2258/sqlservr tcp 0 52 192.168.2.117:22 192.168.2.107:63580 ESTABLISHED 2383/sshd: root@pts tcp 0 0 127.0.0.1:44341 127.0.0.1:1433 ESTABLISHED 2258/sqlservr tcp 0 0 192.168.2.117:22 192.168.2.107:57957 ESTABLISHED 3967/sshd: zdw [pri tcp6 0 0 :::22 :::* LISTEN 1089/sshd tcp6 0 0 ::1:25 :::* LISTEN 2252/master |
pt 显示连接对应的PID与程序名称
[root@c7 shell]# netstat -pt Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 localhost:53476 localhost:ms-sql-s ESTABLISHED 2258/sqlservr tcp 0 0 localhost:ms-sql-s localhost:53476 ESTABLISHED 2258/sqlservr tcp 0 52 c7:ssh bogon:63580 ESTABLISHED 2383/sshd: root@pts |
学习自:
高俊峰《循序渐进Linux》
本文出自 “赵东伟的博客” 博客,请务必保留此出处http://zhaodongwei.blog.51cto.com/4233742/1879591
Linux命令(33):netstat命令-显示网络端口信息