CentOS7开放端口和防火墙操作
1查看防火墙状态:
firewall-cmd --state
systemctl status firewalld.service
2开启防火墙:
systemctl start firewalld.service
3设置开机自启:
systemctl enable firewalld.service
4重启防火墙:
systemctl restart firewalld.service
5查看防火墙设置开机自启是否成功:
systemctl is-enabled firewalld.service;echo $?
6关闭防火墙:
systemctl stop firewalld.service
开端口命令:
打开单个端口:firewall-cmd --zone=public --add-port=80/tcp --permanent
打开多个端口:firewall-cmd --zone=public --add-port=20000-29999/tcp --permanent
--permanent 为永久生效,不加为单次有效(重启失效)
1查看开启端口:
netstat -ntlp 或:firewall-cmd --list-ports
2关闭端口命令:
firewall-cmd --zone=public --remove-port=80/tcp --permanent
3查看端口是否打开
firewall-cmd --zone=public --query-port=80/tcp