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 提供了直观的命令行界面,也允许配置更复杂的防火墙规则。

相关推荐
BK贝壳1 小时前
bool-hybrid-array 的 GPU_opt 与 cjx:一个没显卡就报错的开关,一个把 800 字压到 96 字节的编码
python
BD_Marathon5 小时前
安装Jupyter notebook
ide·python·jupyter
Zlzxzw5 小时前
End-to-End Autonomous Generation of Human Assembly Plans
python
Wellijohn6 小时前
2000 个请求、30% 失败率:我把 Python 批量并发的限流和重试参数算了一遍
后端·python·性能优化
dingdingfish7 小时前
TLPI 第58章 读书笔记:Sockets: Fundamentals of TCP/IP Networks
tcp/ip·socket·ipv4·protocol·network·fundamental
Logintern098 小时前
deep agents 多智能体模式——规划与委派
python·langchain
2601_9679801110 小时前
Python 办公自动化合集 ⑰:Excel自动计算——总和/平均分/最大值
python·pycharm·办公自动化·数据处理·excel自动计算
databook12 小时前
时间序列预测,模型换了一圈为什么没变好
python·数据分析
reasonsummer12 小时前
【教学类-07-17】20261119大3班破译电话号码HTML实际操作(添加“跳过按钮”和“返回按钮”在底部、增加“自编题目+解题”部分)
python·html
2601_9679801115 小时前
Python闭包(Closure)详解
python·作用域·装饰器·函数式编程·闭包