防火墙相关 开放/关闭端口 1 2 firewall-cmd --zone=public --add-port=443/tcp --permanent firewall-cmd --zone=public --remove-port=443/tcp --permanent
查看防火墙所有开放的端口 1 firewall-cmd --zone=public --list-ports
防火墙重新加载 任何修改了防火墙相关的配置 ,都需要重启防火墙,使之生效
关闭防火墙 如果要开放的端口太多,嫌麻烦,可以关闭防火墙,安全性自行评估
1 systemctl stop firewalld.service
查看防火墙状态
端口 查看监听的端口 centos7 默认没有 netstat
命令,需要安装 ‘net-tools’ 工具,yum install -y net-tools
示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 [root@centos7-alexliu ~] 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:4040 0.0.0.0:* LISTEN 67591/ngrok tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 70689/nginx: master tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2474/dnsmasq tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1091/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1087/cupsd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1718/master tcp6 0 0 :::2017 :::* LISTEN 98919/v2raya tcp6 0 0 :::9000 :::* LISTEN 99517/docker-proxy- tcp6 0 0 :::20170 :::* LISTEN 65216/v2ray tcp6 0 0 :::20171 :::* LISTEN 65216/v2ray tcp6 0 0 :::20172 :::* LISTEN 65216/v2ray tcp6 0 0 :::22 :::* LISTEN 1091/sshd tcp6 0 0 ::1:631 :::* LISTEN 1087/cupsd tcp6 0 0 :::32345 :::* LISTEN 65216/v2ray tcp6 0 0 ::1:25 :::* LISTEN 1718/master
检查端口被哪个进程占用
示例
1 2 [root@centos7-alexliu ~] tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 70689/nginx: master
查看进程的详细信息
示例
1 2 3 [root@centos7-alexliu ~] PID TTY STAT TIME COMMAND 70689 ? Ss 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
中止进程 1 2 3 kill 70689kill -9 70689