欢迎来到程序员中文网!

首页 Linux Mysql C++ Python PHP JavaScript 资源下载 动态 开源推荐
我要投稿 投诉建议

Linux 防火墙:firewalld 与 iptables 对比

时间:2026年08月12日 04:46:50 浏览:0

firewalld(推荐)


firewalld 是动态防火墙,修改规则无需重启服务。


# 查看当前区域和规则
firewall-cmd --list-all

# 开放 8080 端口
firewall-cmd --add-port=8080/tcp --permanent
firewall-cmd --reload

# 开放服务(如 http)
firewall-cmd --add-service=http --permanent

iptables(底层工具)


# 允许 SSH
iptables -A INPUT -p tcp --dport 22 -j ACCEPT

# 拒绝所有其他入站
iptables -P INPUT DROP

# 保存规则(CentOS)
service iptables save

实践建议



  • 生产环境建议使用 firewalld,更安全易用

  • 云服务器通常使用安全组,可结合 firewalld 做二次防护

  • 修改前先添加自己的 IP 白名单,避免把自己锁在外面