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

相关推荐
大貔貅喝啤酒1 小时前
Python Requests库教程
自动化测试·python·requests库
copyer_xyf1 小时前
LangChain 调用 LLM
后端·python·agent
copyer_xyf1 小时前
Prompt 组织管理
后端·python·agent
shimly1234562 小时前
python3 uvicorn 是啥?
python
CTA量化套保3 小时前
期货量化程序 time.sleep 卡死:天勤单线程与 deadline 替代
python·区块链
weixin_462446233 小时前
手把手教你用 Bash 脚本自动更新 /etc/hosts —— 自动绑定网卡 IP 与节点名
开发语言·tcp/ip·bash
GIS数据转换器3 小时前
城市排水生命线安全运行监测平台深度解析
java·运维·人工智能·python·安全·数据挖掘·无人机
贤哥哥yyds4 小时前
GBK转UTF\-8编码自动转换工具 使用文档
python
数量技术宅4 小时前
2026量化前沿:从Reddit热帖到Python实战,如何用赫斯特指数(Hurst)狙击虚假突破?
开发语言·python
华如锦4 小时前
面了很多 Java转AI Agent方向,一些面试题总结
java·开发语言·人工智能·python·ai