centos firewalld 封禁某个ip

在 CentOS 系统上使用 firewalld 封禁某个 IP 地址的步骤如下:

  1. 确保 firewalld 已安装并运行:

```

systemctl status firewalld

```

如果没有运行,启动 firewalld:

```

systemctl start firewalld

systemctl enable firewalld

```

  1. 使用 firewall-cmd 命令临时封禁IP:

```

firewall-cmd --add-rich-rule='rule family="ipv4" source address="x.x.x.x" reject' --timeout=0

```

将 x.x.x.x 替换为要封禁的 IP 地址。--timeout=0 使规则持续生效。

  1. 如果需要永久封禁该 IP,请运行:

```

firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="x.x.x.x" reject'

```

  1. 重新加载防火墙使永久规则生效:

```

firewall-cmd --reload

```

  1. 查看当前生效的规则:

```

firewall-cmd --list-rich-rules

```

  1. 如果需要解除 IP 封禁,可以运行:

```

firewall-cmd --remove-rich-rule='rule family="ipv4" source address="x.x.x.x" reject'

```

同样需要 --reload 使规则生效。

通过以上步骤,就可以使用 firewalld 在 CentOS 系统上临时或永久封禁某个来源 IP 地址的访问。firewalld 提供了直观的命令行界面,也允许配置更复杂的防火墙规则。

相关推荐
曲幽3 小时前
FastAPI 身份验证总踩坑?这份 FastAPI Users “避坑指南”请收好
python·fastapi·web·jwt·oauth2·user·authentication
装不满的克莱因瓶4 小时前
掌握 RNN 与 LSTM 模型结构
人工智能·python·rnn·深度学习·神经网络·ai·lstm
何以解忧,唯有..4 小时前
Python包管理工具pip:从入门到精通
开发语言·python·pip
金銀銅鐵4 小时前
用 Tkinter 实现简单的猜数字游戏
后端·python
copyer_xyf4 小时前
Python 模块与包的导入导出
前端·后端·python
ice8130331815 小时前
【Python】Matplotlib折线图绘制
开发语言·python·matplotlib
copyer_xyf5 小时前
Python venv 虚拟环境
前端·后端·python
林爷万福6 小时前
GitHub 开源光谱数据处理项目推荐
python·光纤光谱仪
copyer_xyf6 小时前
Python 如何同时做很多事:进程、线程、协程
前端·后端·python
Full Stack Developme6 小时前
Spring Bean 依赖注入
python·spring·log4j