在CentOS系统中,您可以使用firewall-cmd
命令来管理防火墙规则。以下是添加规则的步骤:
打开终端。
使用firewall-cmd
命令添加规则:
firewall-cmd --permanent --zone=public --add-port=80/tcp
firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.1.100" port protocol="tcp" port="80" accept'
firewall-cmd --permanent --zone=public --add-service=ssh
重新加载防火墙配置以使更改生效:
firewall-cmd --reload
打开终端。
使用firewall-cmd
命令添加永久规则:
firewall-cmd --permanent --zone=public --add-port=80/tcp
- 允许特定IP地址访问:
```bash
firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.1.100" port protocol="tcp" port="80" accept'
firewall-cmd --permanent --zone=public --add-service=ssh
重新加载防火墙配置以使更改生效:
firewall-cmd --reload
查看所有区域的所有规则:
firewall-cmd --list-all-zones
查看特定区域的所有规则:
firewall-cmd --list-all --zone=public
删除特定端口:
firewall-cmd --permanent --zone=public --remove-port=80/tcp
删除特定IP地址访问规则:
firewall-cmd --permanent --zone=public --remove-rich-rule='rule family="ipv4" source address="192.168.1.100" port protocol="tcp" port="80" accept'
删除特定服务:
firewall-cmd --permanent --zone=public --remove-service=ssh
--permanent
选项用于使规则永久生效,如果不加此选项,规则只会在当前会话中有效。--reload
命令用于重新加载防火墙配置,使所有更改生效。通过以上步骤,您可以在CentOS系统中轻松地添加和管理防火墙规则。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:centos如何添加防火墙规则