如题
在一台运行着 Nginx 的服务器上查看 80 端口占用情况
1 2 3 4 5 6
| [root@localhost ~] COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME nginx 3266 root 30u IPv4 10391 TCP *:http (LISTEN) nginx 3267 nginx 30u IPv4 10391 TCP *:http (LISTEN) nginx 3270 nginx 30u IPv4 10391 TCP *:http (LISTEN) [root@localhost ~]
|
如果提示:-bash: lsof: command not found
安装即可
杀死进程
列出所有端口
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| [root@localhost ~] Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:8005 0.0.0.0:* LISTEN 7212/java tcp 0 0 127.0.0.1:8006 0.0.0.0:* LISTEN 3313/java tcp 0 0 0.0.0.0:8009 0.0.0.0:* LISTEN 7212/java tcp 0 0 0.0.0.0:3690 0.0.0.0:* LISTEN 3420/svnserve tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 3147/mysqld tcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN 3365/smbd tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 3328/memcached tcp 0 0 0.0.0.0:11212 0.0.0.0:* LISTEN 3330/memcached tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 2534/portmap tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3266/nginx.conf tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 3266/nginx.conf tcp 0 0 0.0.0.0:8081 0.0.0.0:* LISTEN 3266/nginx.conf tcp 0 0 0.0.0.0:8019 0.0.0.0:* LISTEN 3313/java tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN 2888/vsftpd tcp 0 0 0.0.0.0:8086 0.0.0.0:* LISTEN 3266/nginx.conf tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2858/sshd tcp 0 0 0.0.0.0:8088 0.0.0.0:* LISTEN 7212/java tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3229/sendmail: acce tcp 0 0 0.0.0.0:8090 0.0.0.0:* LISTEN 3313/java tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 3266/nginx.conf tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN 3365/smbd tcp 0 0 0.0.0.0:637 0.0.0.0:* LISTEN 2575/rpc.statd
|
防火墙端口开启/关闭,以下以操作以 80 端口为例
开启端口
方法一
1 2 3
| /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT /etc/init.d/iptables save service iptables restart
|
方法二
1 2 3
| vi /etc/sysconfig/iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT service iptables restart
|
关闭端口
方法一
1 2 3
| /sbin/iptables -I INPUT -p tcp --dport 80 -j DROP /etc/init.d/iptables save service iptables restart
|
方法二
1 2 3
| vi /etc/sysconfig/iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j DROP service iptables restart
|
查看防火墙端口状态
1 2 3 4 5 6 7 8 9 10 11
| [root@centos6 ~] Table: nat Chain PREROUTING (policy ACCEPT) num target prot opt source destination 1 REDIRECT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 redir ports 8080
Chain POSTROUTING (policy ACCEPT) num target prot opt source destination
Chain OUTPUT (policy ACCEPT) num target prot opt source destination
|