端口管理:
应用命令
netstat
参数如下:
-r ,列出路由表
-n,不使用主机名称与服务名称,使用IP与Port Number
-a,列出所有的联机状态
-t,列出所有的TCP数据包联机
-u,列出所有的UTP数据包联机
-l,仅列出有在Listen(监听)的服务之网络状态.
-p,列出PID与Program的文件名
-c,可以设置几秒后自动更新一次,如 -c 5 5秒更新一次.
1)
列出在监听地网络服务
[root@localhost ~]# netstat -tunl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:876 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 :::22 :::* LISTEN
udp 0 0 0.0.0.0:32768 0.0.0.0:*
udp 0 0 0.0.0.0:870 0.0.0.0:*
udp 0 0 0.0.0.0:5353 0.0.0.0:*
udp 0 0 0.0.0.0:873 0.0.0.0:*
udp 0 0 0.0.0.0:111 0.0.0.0:*
udp 0 0 0.0.0.0:631 0.0.0.0:*
udp 0 0 :::32769 :::*
udp 0 0 :::5353 :::*
2)
列出己连接的网络联机状态
[root@localhost ~]# netstat -tun
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 128 ::ffff:192.168.1.55:22 ::ffff:192.168.1.5848878 ESTABLISHED
3)删除己建立或在监听中的程序
[root@localhost ~]# netstat -tunp
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 144 ::ffff:192.168.1.55:22 ::ffff:192.168.1.58:48878 ESTABLISHED 20485/0
kill -9 20485