使用 firewall-cmd 管理 Linux 防火墙<二>
通用选项
-h, --help
:打印简短的帮助文本并退出。-V, --version
:打印 firewalld 的版本信息。-q, --quiet
:不打印状态信息。
状态选项
--state
:返回并打印 firewalld 的状态。--reload
:重新加载防火墙并保持状态信息。--complete-reload
:完全重新加载防火墙并丢失状态信息。--runtime-to-permanent
:将运行时配置保存为永久配置。
拒绝日志选项
--get-log-denied
:打印拒绝日志的值。--set-log-denied=<value>
:设置拒绝日志的值。
可选的参数有:
all
:记录所有被拒绝的包unicast
:只记录单播的被拒绝包broadcast
:只记录广播的被拒绝包multicast
:只记录多播的被拒绝包off
:关闭日志记录
自动助手选项
+ `--get-automatic-helpers`:打印自动助手的值。 + `--set-automatic-helpers=`:设置自动助手的值。可选的参数有:
yes
:启用自动助手,conntrack
为所有支持的协议自动加载助手模块。这是默认行为,但在一些场景下可能存在安全风险,因为自动加载的模块可能会被恶意流量利用。no
:禁用自动助手。阻止conntrack
自动加载协议助手模块。要使用这些模块时,必须手动配置和加载。try
:尝试启用自动助手。折中选项,firewalld
仅在某些情况下尝试自动加载助手模块,但不像yes
那样总是自动加载。
永久选项
--permanent
:永久设置某个选项。适用于标记为[P]
的选项。
区域选项(Zone Options)
--get-default-zone
:打印默认的区域(zone)名称。--set-default-zone=<zone>
:设置默认的区域。--get-active-zones
:打印当前激活的区域。--get-zones
:打印预定义的区域[P]
。--get-services
:打印预定义的服务[P]
。--get-icmptypes
:打印预定义的 ICMP 类型[P]
。--get-zone-of-interface=<interface>
:打印接口绑定的区域名称[P]
。--get-zone-of-source=<source>[/<mask>]|<MAC>|ipset:<ipset>
:打印源地址绑定的区域名称[P]
。--list-all-zones
:列出所有区域中添加或启用的所有内容[P]
。--new-zone=<zone>
:添加一个新区域[P only]
。--new-zone-from-file=<filename> [--name=<zone>]
:从文件添加一个新区域并可以指定可选名称[P only]
。--delete-zone=<zone>
:删除现有的区域[P only]
。--load-zone-defaults=<zone>
:加载区域的默认设置[P only]``[Z]
。--zone=<zone>
:使用此区域进行设置或查询选项,否则使用默认区域。适用于标记为[Z]
的选项。--get-target
:获取区域的目标(target)[P only]``[Z]
。--set-target=<target>
:设置区域的目标[P only]``[Z]
。--info-zone=<zone>
:打印区域的信息。--path-zone=<zone>
:打印区域的文件路径[P only]
。
IPSet 选项
--get-ipset-types
:打印支持的 ipset 类型。--new-ipset=<ipset> --type=<ipset type> [--option=<key>[=<value>]]..
:添加一个新的 ipset[P only]
。--new-ipset-from-file=<filename> [--name=<ipset>]
:从文件添加一个新 ipset 并可以指定可选名称[P only]
。--delete-ipset=<ipset>
:删除现有的 ipset[P only]
。--load-ipset-defaults=<ipset>
:加载 ipset 的默认设置[P only]
。--info-ipset=<ipset>
:打印 ipset 的信息。--path-ipset=<ipset>
:打印 ipset 的文件路径[P only]
。--get-ipsets
:打印预定义的 ipset。--ipset=<ipset> --set-description=<description>
:为 ipset 设置新描述[P only]
。--ipset=<ipset> --get-description
:打印 ipset 的描述[P only]
。--ipset=<ipset> --set-short=<description>
:为 ipset 设置简短描述[P only]
。--ipset=<ipset> --get-short
:打印 ipset 的简短描述[P only]
。--ipset=<ipset> --add-entry=<entry>
:向 ipset 添加新条目[P]
。--ipset=<ipset> --remove-entry=<entry>
:从 ipset 中删除条目[P]
。--ipset=<ipset> --query-entry=<entry>
:返回 ipset 中是否存在该条目[P]
。--ipset=<ipset> --get-entries
:列出 ipset 的条目[P]
。--ipset=<ipset> --add-entries-from-file=<entry>
:从文件向 ipset 添加新条目[P]
。--ipset=<ipset> --remove-entries-from-file=<entry>
:从 ipset 中移除文件中的条目[P]
。
ICMP 类型选项
--new-icmptype=<icmptype>
:添加一个新的 ICMP 类型[P only]
。--new-icmptype-from-file=<filename> [--name=<icmptype>]
:从文件添加一个新的 ICMP 类型并可以指定可选名称[P only]
。--delete-icmptype=<icmptype>
:删除现有的 ICMP 类型[P only]
。--load-icmptype-defaults=<icmptype>
:加载 ICMP 类型的默认设置[P only]
。--info-icmptype=<icmptype>
:打印 ICMP 类型的信息。--path-icmptype=<icmptype>
:打印 ICMP 类型的文件路径[P only]
。--icmptype=<icmptype> --set-description=<description>
:为 ICMP 类型设置新描述[P only]
。--icmptype=<icmptype> --get-description
:打印 ICMP 类型的描述[P only]
。--icmptype=<icmptype> --set-short=<description>
:为 ICMP 类型设置简短描述[P only]
。--icmptype=<icmptype> --get-short
:打印 ICMP 类型的简短描述[P only]
。--icmptype=<icmptype> --add-destination=<ipv>
:为 ICMP 类型启用目的地址[P only]
。--icmptype=<icmptype> --remove-destination=<ipv>
:禁用 ICMP 类型的目的地址[P only]
。--icmptype=<icmptype> --query-destination=<ipv>
:返回是否为 ICMP 类型启用了目的地址[P only]
。--icmptype=<icmptype> --get-destinations
:列出 ICMP 类型中的目的地址[P only]
。
服务选项
--new-service=<service>
:添加一个新服务[P only]
。--new-service-from-file=<filename> [--name=<service>]
:从文件添加一个新服务并可以指定可选名称[P only]
。--delete-service=<service>
:删除现有的服务[P only]
。--load-service-defaults=<service>
:加载服务的默认设置[P only]
。--info-service=<service>
:打印服务的信息。--path-service=<service>
:打印服务的文件路径[P only]
。--service=<service> --set-description=<description>
:为服务设置新描述[P only]
。--service=<service> --get-description
:打印服务的描述[P only]
。--service=<service> --set-short=<description>
:为服务设置简短描述[P only]
。--service=<service> --get-short
:打印服务的简短描述[P only]
。--service=<service> --add-port=<portid>[-<portid>]/<protocol>
:为服务添加新端口[P only]
。--service=<service> --remove-port=<portid>[-<portid>]/<protocol>
:从服务中移除端口[P only]
。--service=<service> --query-port=<portid>[-<portid>]/<protocol>
:返回服务中是否添加了该端口[P only]
。--service=<service> --get-ports
:列出服务的端口[P only]
。--service=<service> --add-protocol=<protocol>
:为服务添加新协议[P only]
。--service=<service> --remove-protocol=<protocol>
:从服务中移除协议[P only]
。--service=<service> --query-protocol=<protocol>
:返回服务中是否添加了该协议[P only]
。--service=<service> --get-protocols
:列出服务的协议[P only]
。--service=<service> --add-source-port=<portid>[-<portid>]/<protocol>
:为服务添加新源端口[P only]
。--service=<service> --remove-source-port=<portid>[-<portid>]/<protocol>
:从服务中移除源端口[P only]
。--service=<service> --query-source-port=<portid>[-<portid>]/<protocol>
:返回服务中是否添加了该源端口[P only]
。--service=<service> --get-source-ports
:列出服务的源端口[P only]
。--service=<service> --add-module=<module>
:为服务添加新模块[P only]
。--service=<service> --remove-module=<module>
:从服务中移除模块[P only]
。--service=<service> --query-module=<module>
:返回服务中是否添加了该模块[P only]
。--service=<service> --get-modules
:列出服务的模块[P only]
。--service=<service> --set-destination=<ipv>:<address>[/<mask>]
:为服务设置目标地址[P only]
。--service=<service> --remove-destination=<ipv>
:禁用服务的目标地址[P only]
。--service=<service> --query-destination=<ipv>:<address>[/<mask>]
:返回服务中是否设置了目标地址[P only]
。--service=<service> --get-destinations
:列出服务中的目标地址[P only]
。
区域(Zone)选项的适配和查询
--list-all
:列出区域中添加或启用的所有内容[P]``[Z]
。--list-services
:列出区域中添加的服务[P]``[Z]
。--timeout=<timeval>
:在指定的时间内启用某个选项,timeval
是一个数字,后跟字母's'
(秒)、'm'
(分钟)或'h'
(小时)。适用于标记为[T]
的选项。--set-description=<description>
:为区域设置新描述[P only]``[Z]
。--get-description
:打印区域的描述[P only]``[Z]
。--set-short=<description>
:为区域设置简短描述[P only]``[Z]
。--get-short
:打印区域的简短描述[P only]``[Z]
。--add-service=<service>
:为区域添加一个服务[P]``[Z]``[T]
。--remove-service=<service>
:从区域移除服务[P]``[Z]
。--query-service=<service>
:返回某个服务是否已添加到区域[P]``[Z]
。--list-ports
:列出区域中添加的端口[P]``[Z]
。--add-port=<portid>[-<portid>]/<protocol>
:为区域添加端口[P]``[Z]``[T]
。--remove-port=<portid>[-<portid>]/<protocol>
:从区域移除端口[P]``[Z]
。--query-port=<portid>[-<portid>]/<protocol>
:返回区域中是否添加了该端口[P]``[Z]
。--list-protocols
:列出区域中添加的协议[P]``[Z]
。--add-protocol=<protocol>
:为区域添加协议[P]``[Z]``[T]
。--remove-protocol=<protocol>
:从区域中移除协议[P]``[Z]
。--query-protocol=<protocol>
:返回区域中是否添加了该协议[P]``[Z]
。--list-source-ports
:列出区域中添加的源端口[P]``[Z]
。--add-source-port=<portid>[-<portid>]/<protocol>
:为区域添加源端口[P]``[Z]``[T]
。--remove-source-port=<portid>[-<portid>]/<protocol>
:从区域中移除源端口[P]``[Z]
。--query-source-port=<portid>[-<portid>]/<protocol>
:返回区域中是否添加了该源端口[P]``[Z]
。--list-icmp-blocks
:列出区域中添加的 ICMP 类型阻止条目[P]``[Z]
。--add-icmp-block=<icmptype>
:为区域添加 ICMP 类型阻止条目[P]``[Z]``[T]
。--remove-icmp-block=<icmptype>
:从区域中移除 ICMP 类型阻止条目[P]``[Z]
。--query-icmp-block=<icmptype>
:返回区域中是否添加了某个 ICMP 类型阻止条目[P]``[Z]
。--add-icmp-block-inversion
:启用区域中 ICMP 阻止条目的反转[P]``[Z]
。--remove-icmp-block-inversion
:禁用区域中 ICMP 阻止条目的反转[P]``[Z]
。--query-icmp-block-inversion
:返回区域中是否启用了 ICMP 阻止条目的反转[P]``[Z]
。--list-forward-ports
:列出区域中添加的 IPv4 转发端口[P]``[Z]
。--add-forward-port=port=<portid>[-<portid>]:proto=<protocol>[:toport=<portid>[-<portid>]][:toaddr=<address>[/<mask>]]
:为区域添加 IPv4 转发端口[P]``[Z]``[T]
。--remove-forward-port=port=<portid>[-<portid>]:proto=<protocol>[:toport=<portid>[-<portid>]][:toaddr=<address>[/<mask>]]
:从区域中移除 IPv4 转发端口[P]``[Z]
。--query-forward-port=port=<portid>[-<portid>]:proto=<protocol>[:toport=<portid>[-<portid>]][:toaddr=<address>[/<mask>]]
:返回区域中是否添加了某个 IPv4 转发端口[P]``[Z]
。--add-masquerade
:为区域启用 IPv4 伪装[P]``[Z]``[T]
。--remove-masquerade
:从区域中禁用 IPv4 伪装[P]``[Z]
。--query-masquerade
:返回区域中是否启用了 IPv4 伪装[P]``[Z]
。--list-rich-rules
:列出区域中添加的富语言规则[P]``[Z]
。--add-rich-rule=<rule>
:为区域添加富语言规则[P]``[Z]``[T]
。--remove-rich-rule=<rule>
:从区域中移除富语言规则[P]``[Z]
。--query-rich-rule=<rule>
:返回区域中是否添加了某个富语言规则[P]``[Z]
。
处理接口绑定的选项
--list-interfaces
:列出绑定到区域的接口[P]``[Z]
。--add-interface=<interface>
:将接口绑定到区域[P]``[Z]
。--change-interface=<interface>
:修改接口的绑定区域[Z]
。--query-interface=<interface>
:查询接口是否绑定到区域[P]``[Z]
。--remove-interface=<interface>
:从区域中移除接口绑定[P]``[Z]
。
处理源地址绑定的选项
--list-sources
:列出绑定到区域的源地址[P]``[Z]
。--add-source=<source>[/<mask>]|<MAC>|ipset:<ipset>
:将源地址绑定到区域[P]``[Z]
。--change-source=<source>[/<mask>]|<MAC>|ipset:<ipset>
:修改源地址的绑定区域[Z]
。--query-source=<source>[/<mask>]|<MAC>|ipset:<ipset>
:查询源地址是否绑定到区域[P]``[Z]
。--remove-source=<source>[/<mask>]|<MAC>|ipset:<ipset>
:从区域中移除源地址绑定[P]``[Z]
。
辅助模块选项
--new-helper=<helper> --module=<module> [--family=<family>]
:添加一个新辅助模块[P only]
。--new-helper-from-file=<filename> [--name=<helper>]
:从文件添加一个新辅助模块并可以指定可选名称[P only]
。--delete-helper=<helper>
:删除现有的辅助模块[P only]
。--load-helper-defaults=<helper>
:加载辅助模块的默认设置[P only]
。--info-helper=<helper>
:打印辅助模块的信息。--path-helper=<helper>
:打印辅助模块的文件路径[P only]
。--get-helpers
:打印预定义的辅助模块。--helper=<helper> --set-description=<description>
:为辅助模块设置新描述[P only]
。--helper=<helper> --get-description
:打印辅助模块的描述[P only]
。--helper=<helper> --set-short=<description>
:为辅助模块设置简短描述[P only]
。--helper=<helper> --get-short
:打印辅助模块的简短描述[P only]
。--helper=<helper> --add-port=<portid>[-<portid>]/<protocol>
:为辅助模块添加新端口[P only]
。--helper=<helper> --remove-port=<portid>[-<portid>]/<protocol>
:从辅助模块移除端口[P only]
。--helper=<helper> --query-port=<portid>[-<portid>]/<protocol>
:返回辅助模块中是否添加了该端口[P only]
。--helper=<helper> --get-ports
:列出辅助模块的端口[P only]
。--helper=<helper> --set-module=<module>
:为辅助模块设置模块[P only]
。--helper=<helper> --get-module
:获取辅助模块的模块[P only]
。--helper=<helper> --set-family={ipv4|ipv6}
:为辅助模块设置协议族[P only]
。--helper=<helper> --get-family
:获取辅助模块的协议族[P only]
。
直接(Direct)选项
--direct
:所有直接操作的首个选项。--get-all-chains
:获取所有链[P]
。--get-chains {ipv4|ipv6|eb} <table>
:获取指定表中的所有链[P]
。--add-chain {ipv4|ipv6|eb} <table> <chain>
:为指定表添加一个新链[P]
。--remove-chain {ipv4|ipv6|eb} <table> <chain>
:从指定表中删除链[P]
。--query-chain {ipv4|ipv6|eb} <table> <chain>
:返回指定表中是否添加了该链[P]
。--get-all-rules
:获取所有规则[P]
。--get-rules {ipv4|ipv6|eb} <table> <chain>
:获取指定表中链上的所有规则[P]
。--add-rule {ipv4|ipv6|eb} <table> <chain> <priority> <arg>...
:为指定表和链添加规则[P]
。--remove-rule {ipv4|ipv6|eb} <table> <chain> <priority> <arg>...
:从指定表和链中删除具有优先级的规则[P]
。--remove-rules {ipv4|ipv6|eb} <table> <chain>
:从指定表和链中删除所有规则[P]
。--query-rule {ipv4|ipv6|eb} <table> <chain> <priority> <arg>...
:返回指定表和链中是否添加了具有优先级的规则[P]
。--passthrough {ipv4|ipv6|eb} <arg>...
:直接传递一个命令(不由 firewalld 追踪)。--get-all-passthroughs
:获取所有被追踪的传递规则[P]
。--get-passthroughs {ipv4|ipv6|eb} <arg>...
:获取被追踪的传递规则[P]
。--add-passthrough {ipv4|ipv6|eb} <arg>...
:添加一个新的被追踪的传递规则[P]
。--remove-passthrough {ipv4|ipv6|eb} <arg>...
:移除一个被追踪的传递规则[P]
。--query-passthrough {ipv4|ipv6|eb} <arg>...
:返回是否添加了该传递规则[P]
。
锁定选项(Lockdown Options)
--lockdown-on
:启用锁定模式。--lockdown-off
:禁用锁定模式。--query-lockdown
:查询锁定模式是否启用。
锁定白名单选项
--list-lockdown-whitelist-commands
:列出所有在白名单中的命令行[P]
。--add-lockdown-whitelist-command=<command>
:将命令添加到白名单[P]
。--remove-lockdown-whitelist-command=<command>
:从白名单中移除命令[P]
。--query-lockdown-whitelist-command=<command>
:查询命令是否在白名单中[P]
。--list-lockdown-whitelist-contexts
:列出白名单中的所有上下文[P]
。--add-lockdown-whitelist-context=<context>
:将上下文添加到白名单[P]
。--remove-lockdown-whitelist-context=<context>
:从白名单中移除上下文[P]
。--query-lockdown-whitelist-context=<context>
:查询上下文是否在白名单中[P]
。--list-lockdown-whitelist-uids
:列出白名单中的所有用户 ID[P]
。--add-lockdown-whitelist-uid=<uid>
:将用户 ID 添加到白名单[P]
。--remove-lockdown-whitelist-uid=<uid>
:从白名单中移除用户 ID[P]
。--query-lockdown-whitelist-uid=<uid>
:查询用户 ID 是否在白名单中[P]
。--list-lockdown-whitelist-users
:列出白名单中的所有用户名称[P]
。--add-lockdown-whitelist-user=<user>
:将用户名添加到白名单[P]
。--remove-lockdown-whitelist-user=<user>
:从白名单中移除用户名[P]
。--query-lockdown-whitelist-user=<user>
:查询用户名是否在白名单中[P]
。
紧急模式(Panic)选项
--panic-on
:启用紧急模式。--panic-off
:禁用紧急模式。--query-panic
:查询紧急模式是否启用。