> 文档中心 > Linux命令之firewall-cmd

Linux命令之firewall-cmd


Linux命令之firewall-cmd

原文链接:https://www.cnblogs.com/diantong/p/9713915.html

firewall-cmd [选项]

firewall-cmd是firewalld守护程序的命令行客户端。它提供了管理运行时和永久配置的接口。firewalld中的运行时配置与永久配置分开。这意味着可以在运行时或永久配置中更改内容。

CnetOS7以后iptables已经被firewalld取代。

(1).选项

1)常规选项

-h,--help  打印帮助-V,--version  打印版本-q,--quiet  不打印状态消息

2)状态选项

--state  检查firewalld守护程序是否处于活动状态--runtime-to-permanent  保存活动运行时配置并使用它覆盖永久配置。它的工作方式是,在配置firewalld时,只进行运行时更改,一旦您对配置感到满意,并且测试了它的工作方式,就可以将配置保存到磁盘。(将当前临时配置保存到磁盘,永久更改)--reload  重新加载防火墙规则并保留状态信息。当前的永久配置将成为新的运行时配置,临时配置将丢失。注意:通过直接接口应用的更改运行时不受影响,因此将保留直到重新启动防火墙守护进程。--complete-reload  完全重新加载防火墙,甚至netfilter(网络过滤器)内核模块。因为状态信息丢失,这很可能会终止活动连接。只有在严重的防火墙问题时才能使用此选项。例如,如果存在状态信息问题,不能使用正确的防护墙规则建立连接。

注意:通过直接接口应用的更改运行时不受影响,因此将保留直到firewalld守护程序完全重新启动。

3)日志拒绝选项

--get-log-denied  打印日志拒绝设置信息--set-log-denied=value  在拒绝之前添加记录规则,并在INPUT,FORWARD和OUTPUT链中删除规则以获取默认规则,并在区域中为已配置的链路层数据包类型添加最终拒绝和丢弃规则。value值包括all,unicast(单播),broadcast(广播),multicast(多播)和off。默认off,禁用日志记录。这是运行时和永久性更改,将会重新加载防火墙以便能添加日志记录规则。

4)自动助手选项

--get-automatic-helpers  打印自动助手设置--set-automatic-helpers=value  为了安全使用iptables和连接跟踪助手,建议关闭Automatic Helpers。但是这可能会对使用netfilter帮助程序的其他服务产生副作用,因为/proc/sys/net/netfilter/nf_conntrack_helper中的sysctl设置将被更改。使用系统设置,将使用内核或sysctl中设置的默认值。vlaue值包括yes,no,system。默认值为system。这是一个运行时和永久性更改,将会重新加载防火墙以便使助手可用。

5)永久选项

--permanent  永久选项--permanent可用于永久设置选项。仅在服务重新启动/重新加载或系统重启后,这些更改才会立即生效。如果没有--permanent选项,更改将只是运行时配置的一部分。如果要在运行时和永久配置中进行更改,请使用带有和不带有—permanent选项的相同调用。可以选择将—permanent选项添加到支持它的所有选项中。

6)区域选项

--get-default-zone 打印连接和接口的默认区域--set-default-zone=zone 为没有选择区域的连接和接口设置默认区域。设置默认区域会更改使用默认区域的连接和接口的区域。这是运行时和永久性更改。--get-active-zones 打印当前活动区域,并使用这些区域中的接口和源。活动区域是绑定一个接口或源的区域。如果没有绑定到区域的接口或源,则将省略相应的行。[--permanent] --get-zones 以空格分隔列表将预定义区域打印[--permanent] --get-services以空格分隔列表将预定义服务打印[--permanent] --get-icmptypes以空格分隔列表将预定义ICMP类型打印[--permanent] --get-zone-of-interface=interface 打印(网卡)接口绑定的区域名称或没有区域[--permanent] --get-zone-of-source=source[/mask]|MAC|ipset:ipset 打印源绑定的区域的名称或没有区域[--permanent] --info-zone=zone 打印关于zone区域的信息[--permanent] --list-all-zones 列出所有区域中添加或启用的所有内容--permanent --new-zone=zone 添加一个新的永久空区域--permanent --new-zone-from-file=filename [--name=zone] 使用可选的名称覆盖,从准备好的区域文件添加新的永久区域--permanent --delete-zone=zone 删除现有的永久区域--permanent --load-zone-defaults=zone 加载区域默认设置或报告NO_DEFAULTS错误--permanent --path-zone=zone 打印区域配置文件的路径--permanent --zone=zone --set-description=description 设置区域的新描述--permanent --zone=zone --get-description 打印区域的描述--permanent --zone=zone --set-short=description 设置区域的简短描述--permanent --zone=zone --get-short 打印区域的简短描述--permanent [--zone=zone] --get-target 获得永久区域的目标--permanent [--zone=zone] --set-target=target 设置永久区域的目标。Target值包含default,ACCEPT,DROP,REJECT

7)修改和查询区域的选项

[--permanent] [--zone=zone] --list-all 列出在zone区域中添加或启用的所有内容。如果省略zone,将使用默认区域。[--permanent] [--zone=zone] --list-services 列出为zone添加的服务,用空格分隔列表。如果省略zone,将使用默认区域。[--permanent] [--zone=zone] --add-service=service [--timeout=timeval] 为zone添加服务。如果省略zone,将使用默认区域。可以多次指定此选项。如果提供超时,则规则将在指定时间内处于活动状态,之后将自动删除。timeval是一个数值(默认单位秒)或数值后跟一个字符s(秒),m(分钟),h(小时)。注意:该服务是firewalld提供的服务之一,要获取支持的服务列表请使用firewall-cmd --get-services。--timeout选项不能与--permanent选项组合使用。[--permanent] [--zone=zone] --remove-service=service 从zone中删除服务。可以多次指定此选项。如果省略zone,将使用默认区域。[--permanent] [--zone=zone] --query-service=service 返回是否已为zone添加服务。如果省略zone,将使用默认区域。如果为true则返回0,否则返回1。[--permanent] [--zone=zone] --list-ports 列出zone区域添加的端口,用空格分隔列表。端口形式为portid[-portid]/protocol,它可以是端口和协议对,也可以是带协议的端口范围。如果省略zone,将使用默认区域。[--permanent] [--zone=zone] --add-port=portid[-portid]/protocol [--timeout=timeval] 添加zone区域的端口。如果省略zone,将使用默认区域。可以多次指定此选项。如果提供超时,则规则将在指定时间内处于活动状态,之后将自动删除。timeval是一个数值(默认单位秒)或数值后跟一个字符s(秒),m(分钟),h(小时)。注意:端口可以是单个端口,也可以是端口范围portid-portid。协议可以是tcp,udp,sctp或dccp。--timeout选项不能与--permanent选项组合使用。[--permanent] [--zone=zone] --remove-port=portid[-portid]/protocol 从zone区域中删除端口。如果省略zone,将使用默认区域。可以多次指定此选项。[--permanent] [--zone=zone] --query-port=portid[-portid]/protocol 返回是否已为zone添加端口。如果省略zone,将使用默认区域。如果为true则返回0,否则返回1。[--permanent] [--zone=zone] --list-protocols 列出为zone区域添加的协议,用空格分隔列表。如果省略zone,将使用默认区域。[--permanent] [--zone=zone] --add-protocol=protocol [--timeout=timeval] 添加zone区域协议。如果省略zone,将使用默认区域。可以多次指定此选项。如果提供超时,则规则将在指定的时间内处于活动状态,之后将自动删除。timeval是一个数值(默认单位秒)或数值后跟一个字符s(秒),m(分钟),h(小时)。注意:协议可以是系统支持的任何协议。请查看/etc/protocols以获取支持的协议。--timeout选项不能与--permanent选项组合使用。[--permanent] [--zone=zone] --remove-protocol=protocol 从zone区域删除协议。如果省略zone,将使用默认区域。可以多次指定此选项。[--permanent] [--zone=zone] --query-protocol=protocol 返回是否为zone区域添加协议。如果省略zone,将使用默认区域。如果为true则返回0,否则返回1。[--permanent] [--zone=zone] --list-source-ports 列出zone区域添加的源端口,用空格分隔列表。端口形式为portid[-portid]/protocol。如果省略zone,将使用默认区域。[--permanent] [--zone=zone] --add-source-port=portid[-portid]/protocol [--timeout=timeval] 添加zone区域的源端口。如果省略zone,将使用默认区域。可以多次指定此选项。如果提供超时,则规则将在指定的时间内处于活动状态,之后将自动删除。timeval是一个数值(默认单位秒)或数值后跟一个字符s(秒),m(分钟),h(小时)。注意:端口可以是单个端口,也可以是端口范围portid-portid。协议可以是tcp,udp,sctp或dccp。--timeout选项不能与--permanent选项组合使用。[--permanent] [--zone=zone] --remove-source-port=portid[-portid]/protocol 从zone区域删除源端口。如果省略zone,将使用默认区域。可以多次指定此选项。[--permanent] [--zone=zone] --query-source-port=portid[-portid]/protocol 返回是否已为zone区域添加源端口。如果省略zone,将使用默认区域。如果为true则返回0,否则返回1。[--permanent] [--zone=zone] --list-icmp-blocks 列出zone区域添加的Internet控制消息协议(ICMP)类型块,用空格分隔列表。如果省略zone,将使用默认区域。[--permanent] [--zone=zone] --add-icmp-block=icmptype [--timeout=timeval] 为zone区域的icmptype添加ICMP块。如果省略zone,将使用默认区域。可以多次指定此选项。如果提供超时,则规则将在指定的时间内处于活动状态,之后将自动删除。timeval是一个数值(默认单位秒)或数值后跟一个字符s(秒),m(分钟),h(小时)。注意icmptype是firewalld支持的icmp类型之一。要获取支持的icmp类型列表:firewall-cmd --get-icmptypes。--timeout选项不能与--permanent选项组合使用。[--permanent] [--zone=zone] --remove-icmp-block=icmptype 从zone区域中删除icmptyoe的ICMP块。如果省略zone,将使用默认区域。可以多次指定此选项。[--permanent] [--zone=zone] --query-icmp-block=icmptype 返回是否为zone添加icmptype的ICMP块。如果省略zone,将使用默认区域。如果为true则返回0,否则返回1。[--permanent] [--zone=zone] --list-forward-ports 列出为zone区域添加的IPv4转发端口,用空格分隔列表。如果省略zone,将使用默认区域。(对于Ipv6转发端口,请使用丰富的语言)[--permanent] [--zone=zone] --add-forward-port= port=portid[-portid]:proto=protocol[:toport=portid[-portid]][:toaddr=address[/mask]] [--timeout=timeval] 为zone区域添加IPv4端口。如果省略zone,将使用默认区域。可以多次指定此选项。如果提供超时,则规则将在指定的时间内处于活动状态,之后将自动删除。timeval是一个数值(默认单位秒)或数值后跟一个字符s(秒),m(分钟),h(小时)。注意:端口可以是单个端口号portid,也可以是端口范围portid-portid。协议可以是tcp,udp,sctp或dccp。目的地址是一个简单的IP地址。--timeout选项不能与--permanent选项组合使用。对于IPv6转发端口,请使用丰富的语言。[--permanent] [--zone=zone] --remove-forward-port= port=portid[-portid]:proto=protocol[:toport=portid[-portid]][:toaddr=address[/mask]] 从zone区域中删除IPv4转发端口。如果省略zone,将使用默认区域。可以多次指定此选项。(对于Ipv6转发端口,请使用丰富的语言)[--permanent] [--zone=zone] --query-forward-port= port=portid[-portid]:proto=protocol[:toport=portid[-portid]][:toaddr=address[/mask]] 返回是否已为zone区域添加IPv4转发端口。如果省略zone,将使用默认区域。如果为true则返回0,否则返回1。(对于Ipv6转发端口,请使用丰富的语言)[--permanent] [--zone=zone] --add-masquerade [--timeout=timeval] 为zone区域启用IPv4伪装。如果省略zone,将使用默认区域。如果提供超时,则规则将在指定的时间内处于活动状态,之后将自动删除。timeval是一个数值(默认单位秒)或数值后跟一个字符s(秒),m(分钟),h(小时)。如果机器是路由器并且通过另一个区域中的接口连接的机器应该能够使用第一个连接,则伪装是有用的。注意:--timeout选项不能与--permanent选项组合使用。对于IPv6伪装,请使用丰富的语言。[--permanent] [--zone=zone] --remove-masquerade 禁用zone区域的IPv4伪装。如果省略zone,将使用默认区域。如果使用超时启用伪装,它也将被禁用。(对于IPv6伪装,请使用丰富的语言)[--permanent] [--zone=zone] --query-masquerade 返回是否已为zone区域启用IPv4伪装。如果省略zone,将使用默认区域。如果为true则返回0,否则返回1。(对于Ipv6伪装,请使用丰富的语言)[--permanent] [--zone=zone] --list-rich-rules 列出为zone区域添加的富语言规则作为,用换行符分隔列表。如果省略zone,将使用默认区域。[--permanent] [--zone=zone] --add-rich-rule=’rule’ [--timeout=timeval] 为zone区域添加丰富的语言规则’rule’。可以多次指定此选项。如果省略zone,将使用默认区域。如果提供超时,则规则将在指定的时间内处于活动状态,之后将自动删除。timeval是一个数值(默认单位秒)或数值后跟一个字符s(秒),m(分钟),h(小时)。注意:有关富语言规则语法,请查看firewalld.richlanguage(5)。--timeout选项不能与--permanent选项组合使用。[--permanent] [--zone=zone] --remove-rich-rule=’rule’ 从zone区域中删除富语言规则’rule’。可以多次指定此选项。如果省略zone,将使用默认区域。[--permanent] [--zone=zone] --query-rich-rule=’rule’ 返回是否为zone区域添加了富语言规则’rule’。 如果省略zone,将使用默认区域。如果为true则返回0,否则返回1。

8)处理接口绑定选项

说明:将接口绑定到区域意味着此区域设置用于通过接口限制流量。接口名称是一个长度不超过16个字符的字符串,不能包含空格,’/’,’!’和’*’。

[--permanent] [--zone=zone] --list-interfaces  列出绑定到zone区域的接口,用空格分隔列表。如果省略zone,将使用默认区域。[--permanent] [--zone=zone] --add-interface=interface  将interface接口绑定到zone区域。如果省略zone,将使用默认区域。作为最终用户,大多数情况下不需要这么做,应为如果费设置NM_CONTROLLED=no,NetworkMnager(或传统网络服务)会自动将接口添加到区域中(根据ifcfg-interface文件的ZONE=option)。只是在没有/etc/sysconfig/network-scripts/ifcfg-interface文件时才应该这样做。如果存在此类文件并使用此--add-interface选项将接口添加到区域,请确保在两种情况下区域都相同,否则行为将是未定义的。[--zone=zone] --change-interface=interface  将interface接口绑定的区域更改为zone区域。如果接口之前没有绑定某个区域,则类似于--add-interface。如果省略zone,将使用默认区域。[--permanent] [--zone=zone] --query-interface=interface  查询interface接口是否绑定到zone区域。如果为true则返回0,否则返回1。[--permanent] --remove-interface=interface  从以前添加的zone区域中删除interface接口的绑定。仅用于删除不受NetworkManager控制的接口:firewall不会尝试更改ifcfg文件中的ZONE设置。这需要确保接口的ifdown不会导致区域设置重置为默认区域。然后在firewalld中仅删除区域绑定。

注意:如果interface接口受NetworkManager控制,则首先连接它以更改使用该接口的连接区域。如果失败,则在firewalld中创建区域绑定,并应用一下限制。对于不受NetworkManager控制的接口,如果文件存在,firewalld会尝试更改ifcfg文件中的ZONE设置。

9)处理来源绑定选项

将源绑定到区域意味着此区域设置将用于限制来此源的流量。

源地址或地址范围是带有IPv4或IPv6掩码的IP地址或网络IP地址,或带有ipset:前缀的MAC地址或ipset。对于IPv4,掩码可以是网络掩码或普通数字。对于IPv6,掩码是普通数字。不支持使用主机名。

[--permanent] [--zone=zone] --list-sources  列出绑定到zone区域的源,用空格分隔列表。如果省略zone,将使用默认区域。[--permanent] [--zone=zone] --add-source=source[/mask]|MAC|ipset:ipset  将source源绑定到zone区域。如果省略zone,将使用默认区域。[--zone=zone] --change-source=source[/mask]|MAC|ipset:ipset  将source源的绑定区域更改为zone区域。如果省略zone,将使用默认区域。[--permanent] [--zone=zone] --query-source=source[/mask]|MAC|ipset:ipset  查询sorce源是否绑定到zone区域。如果为true则返回0,否则返回1。[--permanent] --remove-source=source[/mask]|MAC|ipset:ipset  从先前添加的区域中删除source源的绑定。

10)IP设置选项

--get-ipset-types 打印支持的ipset类型--permanent --new-ipset=ipset --type=type [--family=inet|inet6] [--option=key|value] 添加一个新的永久的空的ipset,指定类型、可选的系列和可选的选项,如timeout,hashsize和maxelem。更多信息请查看ipset(8)手册页。--permanent --new-ipset-from-file=filename [--name=ipset] 使用可选的名称覆盖从准备好的ipset文件添加新的永久ipset--permanent --delete-ipset=ipset 删除现有的永久ipset--permanent --load-ipset-defaults=ipset 加载ipset默认设置或报告NO_DEFAULTS错误[--permanent] --info-ipset=ipset 打印有关ipset的信息。[--permanent] --get-ipsets 打印预定义的ipsets,用空格分隔列表--permanent --ipset=ipset --set-description=description 设置ipset的新描述--permanent --ipset=ipset --get-description 打印ipset的描述--permanent --ipset=ipset --set-short=description 设置ipset的简洁描述--parmanent --ipset=ipset --get-short 打印ipset的简洁描述[--permanent] --ipset=ipset --add-entry=entry 在ipset中添加一个新的条目[--permanent] --ipset=ipset --remove-entry=entry 从ipset中删除一个条目[--permanent] --ipset=ipset --query-entry=entry 返回是否已将条目添加到ipset。如果为true则返回0,否则返回1。[--permanent] --ipset=ipset --get-entries 列出ipset的所有条目。[--permanent] --ipset=ipset --add-entries-from-file=filename 从文件中向ipset添加新条目。对于文件中列出但已在ipset中的所有条目,将打印警告。该文件应包含每行一条目。以哈希或分号开头的行将被忽略。空行也是。[--permanent] --ipset=ipset --remove-entries-from-file=filename 从文件中删除ipset中的现有条目。对于文件中列出但不在ipset中的所有条目,将打印警告。该文件应包含每行一条目。以哈希或分号开头的行将被忽略。空行也是。--permanent --path-ipset=ipset 打印ipset配置文件路径

11)服务选项

[--permanent] --info-service=service 打印有关service服务的信息--permanent --new-service=service 添加一个新的永久的空服务--permanent --new-service-from-file=filename [--name=service] 使用可选的名称覆盖从准备好的服务文件添加新的永久服务--permanent --delete-service=service 删除现有的永久服务--permanent --load-service-defaults=service 加载服务默认设置或报告NO_DEFAULTS错误--permanent --path-service=service 打印服务配置文件路径--permanent --service=service --set-description=description 设置服务的新描述--permanent --service=service --get-description 得到服务的新描述--permanent --service=service --set-short=description 设置服务的简短描述--permanent --service=service --get-short 得到服务的简短描述--permanent --service=service --add-port=portid[-portid]/protocol 为永久服务添加一个新的端口--permanent --service=service --remove-port=portid[-portid]/protocol 为永久服务移除一个端口--permanent --service=service --query-port=portid[-portid]/protocol 返回是否已为永久服务添加端口--permanent --service=service --get-ports 列出永久服务添加的端口--permanent --service=service --add-protocol=protocol 为永久服务添加一个新的协议--permanent --service=service --remove-protocol=protocol 为永久服务移除一个协议--permanent --service=service --query-protocol=protocol 返回是否已为永久服务添加了协议--permanent --service=service --get-protocol 列出永久服务添加的协议--permanent --service=service --add-source-port=protid[-portid]/protocol 为永久服务添加一个新的源端口--permanent --service=service --remove-source-port=protid[-portid]/protocol 为永久服务移除一个源端口--permanent --service=service --query-source-port=protid[-portid]/protocol 返回是否已为永久服务添加源端口--permanent --service=service --get-source-port 列出永久服务的源端口--permanent --service=service --add-module=module 为永久服务添加一个新的模块--permanent --service=service --remove-module=module 为永久服务移除一个新的模块--permanent --service=service --query-module=module 返回是否已为永久服务添加模块--permanent --service=service --get-module 列出永久服务添加的模块--permanent --service=service --set-destination=ipv:address[/mask] 在永久服务中将ipv的目的地设置为address[/mask]--permanent --service=service --remove-destination=ipv 从永久服务中删除ipv的目标--permanent --service=service --query-destination=ipv:address[/mask] 返回是否已为永久服务中ipv的目的地设置为address[/mask]--permanent --service=service --get-destination 列出添加到永久服务的目的地。

12)帮助程序选项

[--permanent] --info-helper=helper 打印有关帮助程序helper的信息--permanent --new-helper=helper --module=nf_conntrack_module [--family=ipv4|ipv6] 添加一个带有模块的新永久帮助程序,并可选择系列定义--permanent --new-helper-from-file=filename [--name=helper] 从准备好的帮助文件中添加一个新的永久帮助程序,并使用可选的名称覆盖--permanent --delete-helper=helper 删除现有的永久帮助程序--permanent --load-helper-defaults=helper 加载帮助程序默认设置或报告NO_DEFAULTS错误--permanent --path-helper=helper 打印帮助程序配置文件地址[--permanent] --get-helpers 打印预定义的帮助程序,用空格分隔列表--permanent --helper=helper --set-description=description 设置帮助程序的描述--permanent --helper=helper --get-description 打印帮助程序的描述--permanent --helper=helper --set-short=description 设置帮助程序的简短描述--permanent --helper=helper --get-short 打印帮助程序的简短描述--permanent --helper=helper --add-port=portid[-portid]/protocol 给永久帮助程序添加一个新的端口--permanent --helper=helper --remove-port=portid[-portid]/protocol 移除永久帮助程序的一个端口--permanent --helper=helper --query-port=portid[-portid]/protocol 返回是否已为永久帮助程序添加端口--permanent --helper=helper --get-port 列出永久帮助程序的端口--permanent --helper=helper --set-module=description 设置帮助程序的模块描述--permanent --helper=helper --get-module 打印帮助程序的模块描述--permanent --helper=helper --set-family=description 设置帮助程序的family描述--permanent --helper=helper --get-family 打印帮助程序的family描述

13)Internet控制消息协议(ICMP)选项

[--permanent] --info-icmptype=icmptype 打印有关icmptype的ICMP类型信息--permanent --new-icmptype=icmptype 添加一个新的永久空ICMP类型--permanent --new-icmptype-from-file=filename [--name-icmptype] 从准备好的ICMP类型文件中添加一个新的永久ICMP类型,并带有可选的名称覆盖--permanent --delete-icmptype=icmptype 删除一个现有的永久ICMP类型--permanent --load-icmptype-defaults=icmptype 加载ICMP类型默认设置或报告NO_DEFAULTS错误。--permanent --icmptype=icmptype --set-description=description 为ICMP类型设置新的描述--permanent --icmptype=icmptype --get-description 打印ICMP类型的描述--permanent --icmptype=icmptype --set-short=description 设置ICMP类型的简短描述--permanent --icmptype=icmptype --get-short 打印ICMP类型的简短描述--permanent --icmptype=icmptype --add-destination=ipv 在永久ICMP类型中启用ipv的目的地,ipv是ipv4或ipv6之一。--permanent --icmptype=icmptype --remove-destination=ipv在永久ICMP类型中禁用ipv的目的地,ipv是ipv4或ipv6之一。--permanent --icmptype=icmptype --query-destination=ipv 返回在永久ICMP类型中是否启用ipv的目的地,ipv是ipv4或ipv6之一。--permanent --icmptype=icmptype --get-destinstions 列出在永久ICMP类型的目的地--permanent --path-icmptype=icmptype 打印ICMP类型的配置文件地址

14)直接选项

直接选项可以更直接地访问防火墙。这些选项要求用户了解基本的iptables概念,即表(filter/mangle/nat/…),链(INPUT/OUTPUT/FORWARD/…),命令(-A/-D/-l/…),参数(-p/-s/-d/-j/…)和目标(ACCEPT/DROP/REJECT/…)。

直接选项仅在不能使用时作为最后手段使用,例如–add-service=service或–add-rich-rule=’rule’。

每个选项的第一个参数必须是ipv4或ipv6或eb。使用ipv4,它将用于IPv4(iptables(8)),ipv6用于IPv6(ip6tables(8)),eb用于以太网桥接(ebtables(8))。

[--permanent] --direct --get-all-chains 得到所有表中添加的所有链。此选项仅涉及先前使用--direct --add-chain添加的链。[--permanent] --direct --get-chains {ipv4|ipv6|eb} table 得到table表中添加的所有链,用空格分隔列表。此选项仅涉及先前使用--direct --add-chain添加的链。[--permanent] --direct --add-chain {ipv4|ipv6|eb} table chain 将具有chain名称的新链添加到table表。确保没有其他具有此名称的链。已存在的基础链用于直接选项,例如INPUT_direct链(详见iptables-save | grep direct)。这些链在区域链之前执行,即在区域中规则之前,将检查放入INPUT_direct的每个规则。[--permanent] --direct --remove-chain {ipv4|ipv6|eb} table chain 从table表格中删除名称为chain的链。只有以前用--direct --add-chain添加的链才能用这种方法删除。[--permanent] --direct --query-chain {ipv4|ipv6|eb} table chain 返回table表中是否存在名为chain的链。如果为true则返回0,否则返回1.此选项仅涉及先前使用--direct --add-chain添加的链。[--permanent] --direct --get-all-rules 得到所有表中的所有链中添加的所有规则,用换行符分隔优先级和参数的列表。此选项仅涉及使用--direct --add-rule添加的规则。[--permanent] --direct --get-rules {ipv4|ipv6|eb} table chain 得到table表中的chain链添加的所有规则,用换行符分隔优先级和参数的列表。此选项仅涉及使用--direct --add-rule添加的规则。[--permanent] --direct --add-rule {ipv4|ipv6|eb} table chain priority args 在table表的chain链中添加一个优先级为priority和参数为args的规则。注意:优先级用于排序规则。优先级0表示在链顶部添加规则,随着有更高的优先级,原有规则将向下移动。具有相同优先级的规则在同一级别,这些规则的顺序不固定,并且可以改变。如果要确保在另一个规则(②)之后添加规则(①),请对本规则(①)使用低优先级,另一个规则(②)使用高级优先级[--permanent] --direct --remove-rule {ipv4|ipv6|eb} table chain priority args 从table表的chain链中删除一个优先级为priority和参数为args的规则。此选项仅涉及使用--direct --add-rule添加的规则。[--permanent] --direct --remove-rules {ipv4|ipv6|eb} table chain 删除table表的chain链的所有规则,此选项仅涉及使用--direct --add-rule添加的规则。[--permanent] --direct --query-rule {ipv4|ipv6|eb} table chain priority args 返回table表的chain链中是否存在优先级为priority和参数为args的规则。如果为true则返回0,否则返回1。此选项仅涉及使用--direct --add-rule添加的规则--direct --passthrough {ipv4|ipv6|eb} args 将命令传递到防火墙。Args可以是所有iptables,ip6tables和ebtables命令行参数。这个命令不被跟踪,这意味着firewalld以后不能提供有关此命令的信息,也不能提供不被跟踪的passthrough表[--permanent] --direct --get-all-passthroughs 获取所有直通规则,用换行符分隔ipv值和参数的列表[--permanent] --direct --get-passthroughs {ipv4|ipv6|eb} 获取ipv值的所有直通规则,用换行符分隔优先级和参数的列表。[--permanent] --direct --add-passthrough {ipv4|ipv6|eb} args 添加ipv值的带有args参数的直通规则[--permanent] --direct --remove-passthrough {ipv4|ipv6|eb} args 删除ipv值的带有args参数的直通规则[--permanent] --direct --query-passthrough {ipv4|ipv6|eb} args 返回是否存在ipv值的带有args参数的直通规则。如果为true则返回0,否则返回1。

15)锁定选项

如果防火墙配置以root身份运行(例如:libvirt)或使用PolicyKit进行身份验证,则本地应用程序或服务可以更改防火墙配置。使用此功能,管理员可以锁定防火墙配置,以便只有锁定白名单上的应用程序才能请求防火墙更改。

锁定访问检查限制正在更改防火墙规则的D-Bus方法。查询,列表(动词)和获取方法不受限制。

锁定功能是firewalld的用户和应用程序策略的非常简单版本,默认情况下处于关闭状态。

--lockdown-on  启用锁定。这是运行时和永久性更改注意:如果启用锁定时firewall-cmd不在锁定白名单里,则无法通过firewall-cmd再次将它警用,需要编辑firewalld.conf--lockdown-off  禁用锁定。这是运行时和永久性更改--query-lockdown  查询是否启用锁定。如果启用则返回0,否则返回1

16)锁定白名单选项

锁定白名单包括命令,context(环境),用户和用户ID。如果白名单上的命令条目以星号’’结尾,则以该命令抬头的所有命令行匹配。如果’’不存在,绝对命令包含参数必须匹配。用户root和其他用户的命令并不总是相同。例如:root使用/bin/firewall-cmd时,在Fedora上使用普通用户/usr/bin/firewall-cmd。context(环境)是在运行的应用程序或服务的安全性(SELinux)环境。要获取正在运行的应用程序的环境,请使用ps -e --context。

警告:如果环境是不受限制的,那么这将打开超过所需应用程序的访问权限。

按一下顺序检查白名单条目:1.context,2.uid,3.user,4.command

[--permanent] --list-lockdown-whitelist-commands 列出白名单中的所有命令行[--permanent] --add-lockdown-whitelist-command=command 添加command到白名单[--permanent] --remove-lockdown-whitelist-command=command 从白名单中移除command[--permanent] --query-lockdown-whitelist-command=command 查询command是否在白名单中。如果true返回0,否则返回1。[--permanent] --list-lockdown-whitelist-contexts 列出白名单中的所有环境[--permanent] --add-lockdown-whitelist-context=context 添加context环境到白名单[--permanent] --remove-lockdown-whitelist-context=context 从白名单中移除context[--permanent] --query-lockdown-whitelist-context=context 查询context是否在白名单中。如果true返回0,否则返回1。[--permanent] --list-lockdown-whitelist-uids 列出白名单中的所有用户ID[--permanent] --add-lockdown-whitelist-uid=uid 添加用户ID uid 到白名单中[--permanent] --remove-lockdown-whitelist-uid=uid 从白名单中移除uid[--permanent] --query-lockdown-whitelist-uid=uid 查询uid是否在白名单中。如果true返回0,否则返回1。[--permanent] --list-lockdown-whitelist-users 列出白名单中的所有用户[--permanent] --add-lockdown-whitelist-user=user 添加用户名user到白名单中[--permanent] --remove-lockdown-whitelist-user=user 从白名单中移除用户名user[--permanent] --query-lockdown-whitelist-user=user 查询用户名user是否存在白名单中。如果true返回0,否则返回1。

17)应急选项

--panic-on  启用应急模式。仅运行时更改。所有传入和传出的数据包都被丢弃,活动连接过期。仅在网络环境出现严重问题时启用此选项。例如,如果机器被黑客入侵。--panic-off  禁用应急模式。仅运行时更改。禁用应急模式后,如果在短时间内启用应急模式,则建立的连接可能会再次起作用。--query-panic  如果启用应急模式则返回0,否则返回1。

(2).实例

查看默认区域

[root@xuexi xf]# firewall-cmd --get-zones    //所有的区域block dmz drop external homeinternal public trusted work[root@xuexi xf]# firewall-cmd --get-default-zone  //查看默认区域public

通过指定网卡接口找到对应的区域,之后可以根据需求进行操作

[root@xuexi xf]# firewall-cmd --get-zone-of-interface=ens33public

通过指定区域查看对应的配置地址,用这个命令就不怕找不到配置文件了

[root@xuexi xf]# firewall-cmd --permanent --path-zone=home/usr/lib/firewalld/zones/home.xml

更改特定网络接口的区域,以及默认区域

[root@xuexi xf]# firewall-cmd --zone=home --change-interface=ens33    //更改特定网络接口的区域Theinterface is under control of NetworkManager, setting zone to'home'.success[root@xuexi xf]# firewall-cmd --get-zone-of-interface=ens33home[root@xuexi xf]# firewall-cmd --reload    //重启firewalldsuccess[root@xuexi xf]# firewall-cmd --get-zone-of-interface=ens33    //还是home,可以知道这是一个运行时和永久性更改home[root@xuexi ~]# firewall-cmd --set-default-zone=home    //更改默认区域success[root@xuexi ~]# firewall-cmd --get-default-zonehome[root@xuexi ~]# firewall-cmd --reload    //重启firewalldsuccess[root@xuexi ~]# firewall-cmd --get-default-zone    //还是home,可以知道这是一个运行时和永久性更改home

查看区域内所包含的服务

[root@xuexi ~]# firewall-cmd --get-services    //所有区域包含的服务RH-Satellite-6 amanda-client amanda-k5-client bacula bacula-client bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc ceph ceph-mon cfengine condor-collector ctdb dhcp dhcpv6 dhcpv6-client dns docker-registry dropbox-lansync elasticsearch freeipa-ldap freeipa-ldaps freeipa-replication freeipa-trust ftp ganglia-client ganglia-master high-availability http https imap imaps ipp ipp-client ipsec iscsi-target kadmin kerberos kibana klogin kpasswd kshell ldap ldaps libvirt libvirt-tls managesieve mdns mosh mountd ms-wbt mssql mysql nfs nfs3 nrpe ntp openvpn ovirt-imageio ovirt-storageconsole ovirt-vmconsole pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy proxy-dhcp ptp pulseaudio puppetmaster quassel radius rpc-bind rsh rsyncd samba samba-client sane sip sips smtp smtp-submission smtps snmp snmptrap spideroak-lansync squid ssh synergy syslog syslog-tls telnet tftp tftp-client tinc tor-socks transmission-client vdsm vnc-server wbem-https xmpp-bosh xmpp-client xmpp-local xmpp-server[root@xuexi ~]# firewall-cmd --list-services    //默认区域包含的服务ssh dhcpv6-client[root@xuexi ~]# firewall-cmd --zone=home --list-services    //指定区域包含的服务ssh mdns samba-client dhcpv6-client

永久添加一个服务到指定区域

[root@xuexi ~]# firewall-cmd --zone=public --query-service=httpsno[root@xuexi ~]# firewall-cmd --permanent --zone=public --add-service=https  //如果没有--permanent,那么只有运行时有效。success[root@xuexi ~]# firewall-cmd --zone=public --query-service=httpsyes

查看指定区域的端口

[root@xuexi ~]# firewall-cmd --list-ports  //默认区域的端口22/tcp[root@xuexi ~]# firewall-cmd --zone=home --list-ports  //home区域没有端口,所以是空行 //这是一个空行

永久添加指定端口/指定协议到指定区域

[root@xuexi ~]# firewall-cmd --permanent --zone=public --add-port=8080-8081/tcp  //没有--permanent将是一次运行时添加success[root@xuexi ~]# firewall-cmd --zone=public --list-ports22/tcp[root@xuexi ~]# firewall-cmd --reload  //必须重启才能使用新添加的端口success[root@xuexi ~]# firewall-cmd --zone=public --list-ports22/tcp 8080-8081/tcp

永久从指定区域移除指定端口/指定协议

[root@xuexi ~]# firewall-cmd --permanent --zone=public --remove-port=8080-8081/tcp  //没有--permanent将是一次运行时移除success[root@xuexi ~]# firewall-cmd --zone=public --list-ports22/tcp 8080-8081/tcp[root@xuexi ~]# firewall-cmd --reload   //必须重启才能使移除生效success[root@xuexi ~]# firewall-cmd --zone=public --list-ports22/tcp

禁止指定IP地址访问该服务器,多用于阻止黑客暴力破解

//添加一条富语言规则,使用"man firewalld.richlanguage"可详细查看富语言规则使用方法。
//此处没有指定区域,使用的是默认区域public[root@xuexi ~]# firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.128.137" drop'success[root@xuexi ~]# firewall-cmd --reload  //重启firewalldsuccess[root@xuexi ~]# firewall-cmd --list-rich-rules  //查看默认区域public的规则信息rule family="ipv4" source address="192.168.128.137" drop

删除一条指定的规则

//这里的规则不要自己写,直接使用鼠标中间键复制或其他方法复制,不然容易写错[root@xuexi ~]# firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address="192.168.128.137" drop'success[root@xuexi ~]# firewall-cmd --reload  //重启success[root@xuexi ~]# firewall-cmd --list-rich-rules  //已经没有了