Linux_常用网络命令

netstat

查看本机开启的端口

[root@localhost ~]# netstat -tuln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 :::11211 :::* LISTEN
tcp 0 0 :::80 :::* LISTEN

查看本机有哪些程序开启的端口

[root@localhost ~]# netstat -tulnp
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:3306 0.0.0.0:* LISTEN 2359/mysqld 
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 1563/memcached 
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1490/sshd 
tcp 0 0 :::11211 :::* LISTEN 1563/memcached 
tcp 0 0 :::80 :::* LISTEN 21025/httpd 
tcp 0 0 :::22 :::* LISTEN 1490/sshd 
udp 0 0 0.0.0.0:11211 0.0.0.0:* 1563/memcached 
udp 0 0 :::11211 :::* 1563/memcached
#比之前的命令多了一个“-p”选项,结果多了“PID/程序名”,可以知道是哪个程序占用了端口

查看所有连接

[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:3306 0.0.0.0:* LISTEN 
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 
tcp 0 0 117.79.130.170:80 78.46.174.55:58815 SYN_RECV 
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 
tcp 0 0 117.79.130.170:22 124.205.129.99:10379 ESTABLISHED 
tcp 0 0 117.79.130.170:22 124.205.129.99:11811 ESTABLISHED
…省略部分内容…
udp 0 0 0.0.0.0:11211 0.0.0.0:* 
udp 0 0 :::11211 :::* 
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 9761 @/var/run/hald/dbus-fr41WkQn1C
…省略部分内容…
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容