netstat
查看本機(jī)開啟的端口
[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
查看本機(jī)有哪些程序開啟的端口
[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
#比之前的命令多了一個(gè)“-p”選項(xiàng)稳懒,結(jié)果多了“PID/程序名”,可以知道是哪個(gè)程序占用了端口
查看所有連接
[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
…省略部分內(nèi)容…
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
…省略部分內(nèi)容…