centOS7配置防火墙白名单
时间: 2024-02-29 22:47:18 浏览: 89
配置 CentOS7 防火墙白名单的步骤如下:
1. 查看已经启用的防火墙规则:sudo firewall-cmd --list-all
2. 添加允许通过的端口:sudo firewall-cmd --zone=public --add-port=端口号/tcp --permanent
3. 添加允许通过的IP地址:sudo firewall-cmd --zone=public --add-source=IP地址/24 --permanent
4. 重新载入防火墙规则:sudo firewall-cmd --reload
需要注意的是,以上命令中的端口号和IP地址需要根据实际情况进行修改。
相关问题
centos7查询防火墙白名单
在CentOS 7系统中,防火墙规则通常存储在iptables或firewalld软件中。如果你使用的是iptables,你可以查看白名单(允许列表)的规则通过以下步骤:
1. 打开终端并输入命令:
```bash
sudo iptables -L -n --line-numbers --list-services --check-state RELATED,ESTABLISHED,INPUT -j ACCEPT
```
这将显示所有已配置为接受连接的入站规则,这些规则通常包含了服务名。
2. 如果你想要查看针对特定端口的服务白名单,可以添加`-p`选项,比如查询80端口(HTTP):
```bash
sudo iptables -L -n --line-numbers --list-services -p tcp --dport 80 -j ACCEPT
```
对于firewalld,操作类似但稍微有所不同:
1. 首先,确认你在使用firewalld而非iptables:
```bash
firewall-cmd --permanent --get-active-zones
```
2. 然后查看允许的规则:
```bash
firewall-cmd --list-all --permanent --service http --zone=public
```
3. 或者查看针对端口的规则:
```bash
firewall-cmd --permanent --list-all --filter-service=http --direction=in
firewall-cmd --reload
```
CentOS 7添加防火墙白名单
在CentOS 7中添加防火墙白名单可以通过以下步骤完成:
1. **安装firewalld**(如果尚未安装):
```bash
sudo yum install firewalld -y
```
2. **启动并启用firewalld服务**:
```bash
sudo systemctl start firewalld
sudo systemctl enable firewalld
```
3. **添加端口到白名单**:
假设你要添加端口80和443到白名单,可以使用以下命令:
```bash
sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --permanent --add-port=443/tcp
```
4. **添加服务到白名单**:
如果你想添加某个服务(例如HTTP和HTTPS)到白名单,可以使用以下命令:
```bash
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
```
5. **重新加载防火墙配置**:
```bash
sudo firewall-cmd --reload
```
6. **验证防火墙规则**:
你可以使用以下命令来验证防火墙规则是否已正确添加:
```bash
sudo firewall-cmd --list-all
```
通过以上步骤,你就可以在CentOS 7中添加防火墙白名单了。
阅读全文
相关推荐














