firewall-cmd --zone=public --add-port=80/tcp --permanent
出现 success 表明持久化成功,但此时并未添加规则哦!
同时执行如下两条命令才表示既添加规则又永久保存(重启后会自动载入持久化的规则):
## add rule and take effect now
sudo firewall-cmd --add-port 8889/tcp
## persist rule to file only, not add it now
sudo firewall-cmd --add-port 8889/tcp --permanent
命令含义:
--zone #作用域
--add-port=80/tcp # 添加端口,格式为:端口 / 通讯协议
--permanent #永久生效,没有此参数重启后失效
上述操作不需要重启防火墙即可生效哦。
另,如何查看当前防火墙允许的端口列表呢?
### how to list all fire rules and add a tcp port to allow rules
sudo firewall-cmd --list-all
确实需要重启防火墙,则使用如下命令:
systemctl restart firewalld.service
网友评论