大网数据广告活动
服务器运维问答

How do I display the entire firewalld state?

· 52CE 我爱测

I'm trying to work out why a firewall is not behaving as I think I've asked it to behave, and thus trying to work out how to get firewalld to show its complete set of rules, in some format resembling an iptables configuration fil…

问题原文

原帖链接 · Norman Gray · CC BY-SA 4.0

I'm trying to work out why a firewall is not behaving as I think I've asked it to behave, and thus trying to work out how to get firewalld to show its complete set of rules, in some format resembling an iptables configuration file. Or some other format – I don't much care – as long as it's as least as readable as an iptables or pf configuration (ie, this is a pretty low bar to clear!).

  • Commands like firewall-cmd --list-all ‘List everything added for or enabled in zone.’ But that just lists interfaces, services, and so on, with no further detail. I can't see a --list-all-no-really-everything option.
  • I thought I had found it when I read about the direct rules, but I see that that only applies to rules added as extra ‘direct’ rules, and isn't the trapdoor into the engine room that it first appeared.
  • I see the configuration files in /etc/firewalld and the defaults in /usr/lib/firewalld. But while this is promising at first glance, and beautifully commented, it doesn't seem to actually tell me much about the current state. Questions like this one are about exporting rules (for moving elsewhere), and suggests that this is all there is (I'm guessing that ports mentioned in services mentioned in the public zone are blocked for incoming...?).

My understanding (correct me if I'm wrong) is that firewalld has something iptables-like inside, which is doing all the actual work, and it has some sort of state which --reload can find and, well,... reload. That is the state which I'm hoping to find.

Perhaps I'm dim, but I find the overall level of indirection and helpfulness of firewall-cmd completely unintelligible. Yes, famously ‘every problem in computing science can be solved by adding another layer of indirection’, but sometimes this can be taken to extremes.

I may not have a firewall problem at all, but I can't work out enough about the firewall state to rule that out. Is there a case for switching to iptables (I wonder in desperation)? It's more fuss to set up, and easy to get things wrong, but at least I have some idea what's happening.

I'm very open to frame challenges, or to being told I'm barking up the wrong tree.

已采纳解答

原帖链接 · Bob · CC BY-SA 4.0

I would generally recommend to look at the actual firewall rule sets the Linux kernel is running, rather than trying to diagnose more complex firewall issues from "user-friendly" tools such as firewalld (or similarly UFW and others) and the abstraction layer such tools provide. Often once you understand the underlying issues you can easily resolve them in a matter supported by those tools.

Although some people like [sudo] iptables-save for me the command [sudo] iptables -L -v -n is better.
Often when discussing configurations it is useful to use the --line-numbers option as well to see line numbers. Mentioning rule #X makes a discussion somewhat easier. Remember though that by default iptables only displays the FILTER table and you need to specify other tables with the -t [ nat | mangle | raw] switch.

When the nftables backend is used by firewalld, use nft list ruleset instead.

(For me firewalld is effectively yet another front-end to create rulesets that will be loaded into the Linux netfilter kernel modules. You can still manipulate those backends with their native and more low level tools such as iptables or the more modern nftables successor tools. The picture below shows what other backends firewalld can use and bring together.)

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-02-21)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。