答案是查看Linux防火墙状态需区分firewalld和iptables:使用systemctl或firewall-cmd检查firewalld运行状态,用iptables -L -n -v查看iptables规则,确认服务类型后选择对应命令可快速定位网络问题。

Linux系统中防火墙的管理主要依赖于iptables或firewalld,具体使用哪种工具取决于系统版本和发行版。查看防火墙状态和规则是日常运维中的基本操作,下面介绍常见方法。
根据系统使用的防火墙服务,选择对应命令:
systemctl is-active firewalld —— 查看是否运行
systemctl is-enabled firewalld —— 查看是否开机自启
也可使用:firewall-cmd --state 直接返回running或not running
执行 iptables -L -n -v 可列出当前所有规则,若无输出或提示未加载模块,则可能防火墙未启用
部分系统支持 service iptables status(如CentOS 6)
明确当前生效的访问控制规则是排查网络问题的关键。
firewall-cmd --list-all —— 显示当前区域的完整配置(包括服务、端口、伪装等)
firewall-cmd --list-ports —— 仅列出开放的端口
firewall-cmd --list-services —— 列出允许的服务
iptables -L -n -v —— 以数字形式显示所有链的规则,避免反向解析影响速度
iptables -S —— 显示规则的原始格式(类似保存的配置)
可加参数指定表,例如:iptables -t nat -L -n 查看NAT表规则
临时或永久调整防火墙运行状态:
启动:systemctl start firewalld
停止:systemctl stop firewalld
禁用(不启动):systemctl disable firewalld
启用并开机自启:systemctl enable firewalld
清空规则并保存(相当于关闭):
iptables -F
service iptables save (或 /etc/init.d/iptables save)
实际运维中常需开放端口或服务:
开放某个端口:
firewall-cmd --add-port=80/tcp --permanent
开放某个服务(如http):
firewall-cmd --add-service=http --permanent
重新加载使配置生效:
firewall-cmd --reload
注意:不加 --permanent 参数则为临时规则,重启后失效
基本上就这些。掌握查看状态和规则的核心命令,能快速定位网络访问问题。不同发行版细节略有差异,关键是先确认系统使用的是firewalld还是iptables。
以上就是Linux防火墙怎么查看_Linux防火墙状态查看与规则管理的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号