CentOS7开启防火墙及特定端口
1. 首先查看防火墙状态
[root@localhost ~] firewall-cmd --state
not running
2. 开启|重启|自启防火墙
开启防火墙
[root@localhost ~] systemctl start firewalld.service
重启防火墙
[root@localhost ~] systemctl restart firewalld.service
开机自启
[root@localhost ~] systemctl enable firewalld.service
3. 查看防火墙设置开机自启是否成功
[root@localhost ~] systemctl is-enabled firewalld.service;echo $?
enabled
0
4. 开启特定端口
开端口命令:firewall-cmd --zone=public --add-port=80/tcp --permanent
重启防火墙:systemctl restart firewalld.service
命令含义:
--zone # 作用域
--add-port=80/tcp # 添加端口,格式为:端口/通讯协议