From Fedora Project Wiki
Line 113: Line 113:
=== 使用 firewall-cmd ===
=== 使用 firewall-cmd ===


The command line client '''firewall-cmd''' supports all firewall features. For status and query modes, there is no output, but the command returns the state.
命令行工具 '''firewall-cmd''' 支持全部防火墙特性。对于状态和查询模式,命令只返回状态,没有其他输出。


==== 一般应用 ====
==== 一般应用 ====


* Get the status of firewalld
* 获取 firewalld 状态
   firewall-cmd --state
   firewall-cmd --state


This returns the status of firewalld, there is no output. To get a visual state use:
此举返回 firewalld 的状态,没有任何输出。可以使用以下方式获得状态输出:
   firewall-cmd --state && echo "Running" || echo "Not running"
   firewall-cmd --state && echo "Running" || echo "Not running"


* Reload the firewall without loosing state information:
* 在不改变状态的条件下重新加载防火墙:
   firewall-cmd --reload
   firewall-cmd --reload


If you are using '''--complete-reload''' instead, the state information will be lost. This option should only be used in case of severe firewall problems for example if there are state information problems that no connection can be established but the firewall rules are correct.
如果你使用 '''--complete-reload''' ,状态信息将会丢失。这个选项应当仅用于处理防火墙问题时,例如,状态信息和防火墙规则都正常,但是不能建立任何连接的情况。


* Get a list of all supported zones
* Get a list of all supported zones

Revision as of 14:53, 9 July 2013

使用 FirewallD 构建动态防火墙

FirewallD 提供了支持网络/防火墙区域(zone)定义网络链接以及接口安全等级的动态防火墙管理工具。它支持 IPv4, IPv6 防火墙设置以及以太网桥接,并且拥有运行时配置和永久配置选项。它也支持允许服务或者应用程序直接添加防火墙规则的接口。 以前的 system-config-firewall/lokkit 防火墙模型是静态的,每次修改都要求防火墙完全重启。这个过程包括内核 netfilter 防火墙模块的卸载和新配置所需模块的装载等。而模块的卸载将会破坏状态防火墙和确立的连接。


相反,firewall daemon 动态管理防火墙,不需要重启整个防火墙便可应用更改。因而也就没有必要重载所有内核防火墙模块了。不过,要使用 firewall daemon 就要求防火墙的所有变更都要通过该守护进程来实现,以确保守护进程中的状态和内核里的防火墙是一致的。另外,firewall daemon 无法解析由 ip*tables 和 ebtables 命令行工具添加的防火墙规则。

守护进程通过 D-BUS 提供当前激活的防火墙设置信息,也通过 D-BUS 接受使用 PolicyKit 认证方式做的更改。

“守护进程”

应用程序、守护进程和用户可以通过 D-BUS 请求启用一个防火墙特性。特性可以是预定义的防火墙功能,如:服务、端口和协议的组合、端口/数据报转发、伪装、ICMP 拦截或自定义规则等。该功能可以启用确定的一段时间也可以再次停用。

通过所谓的直接接口,其他的服务(例如 libvirt )能够通过 iptables 变元(arguments)和参数(parameters)增加自己的规则。

amanda 、ftp 、samba 和 tftp 服务的 netfilter 防火墙助手也被“守护进程”解决了,只要它们还作为预定义服务的一部分。附加助手的装载不作为当前接口的一部分。由于一些助手只有在由模块控制的所有连接都关闭后才可装载。因而,跟踪连接信息很重要,需要列入考虑范围。

静态防火墙(system-config-firewall/lokkit)

使用 system-config-firewall 和 lokkit 的静态防火墙模型实际上仍然可用并将继续提供,但却不能与“守护进程”同时使用。用户或者管理员可以决定使用哪一种方案。

在软件安装,初次启动或者是首次联网时,将会出现一个选择器。通过它你可以选择要使用的防火墙方案。其他的解决方案将保持完整,可以通过更换模式启用。

firewall daemon 独立于 system-config-firewall,但二者不能同时使用。

什么是区域?

网络区域定义了网络连接的可信等级。这是一个一对多的关系,这意味着一次连接可以仅仅是一个区域的一部分,而一个区域可以用于很多连接。 大多数区域是可变的,但是也有一些不可变的区域。不可变区域不能定制,并且也没有办法对它们进行重载。

预定义的服务

服务是端口和/或协议入口的组合。备选内容包括 netfilter 助手模块以及 IPv4、IPv6地址。

端口和协议

定义了 tcp 或 udp 端口,端口可以是一个端口或者端口范围。

ICMP 阻塞

可以选择 Internet 控制报文协议的报文。这些报文可以是信息请求亦可是对信息请求或错误条件创建的响应。

伪装

私有网络地址可以被映射到公开的IP地址。这是一次正规的地址转换。

端口转发

端口可以映射到另一个端口以及/或者其他主机。

哪个区域可用?

由firewalld 提供的区域按照从不信任到信任的顺序排序。

丢弃 (不可变)

任何流入网络的包都被丢弃,不作出任何响应。只允许流出的网络连接。

阻塞 (不可变)

任何进入的网络连接都被拒绝,并返回 IPv4 的 icmp-host-prohibited 报文或者 IPv6 的 icmp6-adm-prohibited 报文。只允许由该系统初始化的网络连接。

公开

用以可以公开的部分。你认为网络中其他的计算机不可信并且可能伤害你的计算机。只允许选中的连接接入。(You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.)

外部

用在路由器等启用伪装的外部网络。你认为网络中其他的计算机不可信并且可能伤害你的计算机。只允许选中的连接接入。

隔离区(dmz)

用以允许隔离区(dmz)中的电脑有限地被外界网络访问。只接受被选中的连接。

工作

用在工作网络。你信任网络中的大多数计算机不会影响你的计算机。只接受被选中的连接。

家庭

用在家庭网络。你信任网络中的大多数计算机不会影响你的计算机。只接受被选中的连接。

内部

用在内部网络。你信任网络中的大多数计算机不会影响你的计算机。只接受被选中的连接。

受信任的 (不可变)

允许所有网络连接。

我应该选用哪个区域?

例如,公共的 WIFI 连接应该主要为不受信任的,家庭的有线网络应该是相当可信任的。根据与你使用的网络最符合的区域进行选择。

如何配置或者增加区域?

你可以使用任何一种 firewalld 配置工具来配置或者增加区域,以及修改配置。工具有例如 firewall-config 这样的图形界面工具, firewall-cmd 这样的命令行工具,以及D-BUS接口。或者你也可以在配置文件目录中创建或者拷贝区域文件。 @PREFIX@/lib/firewalld/zones 被用于默认和备用配置,/etc/firewalld/zones 被用于用户创建和自定义配置文件。

如何为网络连接设置或者修改区域

区域设置以 ZONE= 选项 存储在网络连接的ifcfg文件中。如果这个选项缺失或者为空,firewalld 将使用配置的默认区域。

如果这个连接受到 NetworkManager 控制,你也可以使用 nm-connection-editor 来修改区域。

由 NetworkManager 控制的网络连接

防火墙不能够通过 NetworkManager 显示的名称来配置网络连接,只能配置网络接口。因此在网络连接之前 NetworkManager 将配置文件所述连接对应的网络接口告诉 firewalld 。如果在配置文件中没有配置区域,接口将配置到 firewalld 的默认区域。如果网络连接使用了不止一个接口,所有的接口都会应用到 fiwewalld。接口名称的改变也将由 NetworkManager 控制并应用到firewalld。

为了简化,自此,网络连接将被用作与区域的关系。

如果一个接口断开了, NetworkManager 也将告诉 firewalld 从区域中删除该接口。

当 firewalld 由 systemd 或者 init 脚本启动或者重启后,firewalld 将通知 NetworkManager 把网络连接增加到区域。

由脚本控制的网络

对于由网络脚本控制的连接有一条限制:没有守护进程通知 firewalld 将连接增加到区域。这项工作仅在 ifcfg-post 脚本进行。因此,此后对网络连接的重命名将不能被应用到firewalld。同样,在连接活动时重启 firewalld 将导致与其失去关联。现在有意修复此情况。最简单的是将全部未配置连接加入默认区域。

区域定义了本区域中防火墙的特性:

使用 firewalld

你可以通过图形界面工具 firewall-config 或者命令行客户端 firewall-cmd 启用或者关闭防火墙特性。

使用 firewall-cmd

命令行工具 firewall-cmd 支持全部防火墙特性。对于状态和查询模式,命令只返回状态,没有其他输出。

一般应用

  • 获取 firewalld 状态
 firewall-cmd --state

此举返回 firewalld 的状态,没有任何输出。可以使用以下方式获得状态输出:

 firewall-cmd --state && echo "Running" || echo "Not running"
  • 在不改变状态的条件下重新加载防火墙:
 firewall-cmd --reload

如果你使用 --complete-reload ,状态信息将会丢失。这个选项应当仅用于处理防火墙问题时,例如,状态信息和防火墙规则都正常,但是不能建立任何连接的情况。

  • Get a list of all supported zones
 firewall-cmd --get-zones

This command prints a space separated list.

  • Get a list of all supported services
 firewall-cmd --get-services

This command prints a space separated list.

  • Get a list of all supported icmptypes
 firewall-cmd --get-icmptypes

This command prints a space separated list.

  • List all zones with the enabled features.
 firewall-cmd --list-all-zones

The output format is:

 <zone>
   interfaces: <interface1> ..
   services: <service1> ..
   ports: <port1> ..
   forward-ports: <forward port1> ..
   icmp-blocks: <icmp type1> ..
   
   ..
  • Print zone <zone> with the enabled features. If zone is omitted, the default zone will be used.
 firewall-cmd [--zone=<zone>] --list-all
  • Get the default zone set for network connections
 firewall-cmd --get-default-zone
  • Set the default zone
 firewall-cmd --set-default-zone=<zone>

All interfaces that are located in the default zone will be pushed in the new default zone, that defines the limitations for new external initiated connection attempts. Active connections are not affected.

  • Get active zones
 firewall-cmd --get-active-zones

The command prints the interfaces that are set to be part of a zone in this form:

 <zone1>: <interface1> <interface2> ..
 <zone2>: <interface3> ..
  • Get zone related to an interface
 firewall-cmd --get-zone-of-interface=<interface>

This prints the zone name, if the interface is part of a zone

  • Add an interface to a zone
 firewall-cmd [--zone=<zone>] --add-interface=<interface>

Add an interface to a zone, if it was not in a zone before. If the zone options is omitted, the default zone will be used. The interfaces are reapplied after reloads.

  • Change the zone an interface belongs to
 firewall-cmd [--zone=<zone>] --change-interface=<interface>

This is similar to the --add-interface options, but pushes the interface in the new zone even if it was in another zone before.

  • Remove an interface from a zone
 firewall-cmd [--zone=<zone>] --remove-interface=<interface>
  • Query if an interface is in a zone
 firewall-cmd [--zone=<zone>] --query-interface=<interface>

Returns if the interface is in the zone. There is no output.

  • List the enabled services in a zone
 firewall-cmd [ --zone=<zone> ] --list-services
  • Enable panic mode to block all network traffic in case of emergency
 firewall-cmd --enable-panic
  • Disable panic mode
 firewall-cmd --disable-panic
  • Query panic mode
 firewall-cmd --query-panic

This returns the state of the panic mode, there is no output. To get a visual state use

 firewall-cmd --query-panic && echo "On" || echo "Off"

处理运行时区域

In the runtime mode the changes to zones are not permanent. The changes will be gone after reload or restart.

  • Enable a service in a zone
 firewall-cmd [--zone=<zone>] --add-service=<service> [--timeout=<seconds>]

This enables a service in a zone. If zone is not set, the default zone will be used. If timeout is set, the service will only be enabled for the amount of seconds in the zone. If the service is already active, there will be no warning message.

  • Example: Enable ipp-client service for 60 seconds in the home zone:
 firewall-cmd --zone=home --add-service=ipp-client --timeout=60
  • Example: Enable the http service in the default zone:
 firewall-cmd --add-service=http
  • Disable a service in a zone
 firewall-cmd [--zone=<zone>] --remove-service=<service>

This disables a service in a zone. If zone is not set, the default zone will be used.

  • Example: Disable http service in the home zone:
 firewall-cmd --zone=home --remove-service=http

The service will be disabled in the zone. If the service is not enabled in the zone, there will be an warning message.

  • Query if a service is enabled in a zone
 firewall-cmd [--zone=<zone>] --query-service=<service>

This returns 1 if the service is enabled in the zone, otherwise 0. There is no output.

  • Enable a port and protocol combination in a zone
 firewall-cmd [--zone=<zone>] --add-port=<port>[-<port>]/<protocol> [--timeout=<seconds>]

This enables a port and protocol combination. The port can be a single port <port> or a port range <port>-<port>. The protocol can be either tcp or udp.

  • Disable a port and protocol combination in a zone
 firewall-cmd [--zone=<zone>] --remove-port=<port>[-<port>]/<protocol>
  • Query if a port and protocol combination in enabled in a zone
 firewall-cmd [--zone=<zone>] --query-port=<port>[-<port>]/<protocol>

This command returns if it is enabled, there is no output.

  • Enable masquerading in a zone
 firewall-cmd [--zone=<zone>] --add-masquerade

This enables masquerading for the zone. The addresses of a private network are mapped to and hidden behind a public IP address. This is a form of address translation and mostly used in routers. Masquerading is IPv4 only because of kernel limitations.

  • Disable masquerading in a zone
 firewall-cmd [--zone=<zone>] --remove-masquerade
  • Query masquerading in a zone
 firewall-cmd [--zone=<zone>] --query-masquerade

This command returns if it is enabled, there is no output.

  • Enable ICMP blocks in a zone
 firewall-cmd [--zone=<zone>] --add-icmp-block=<icmptype>

This enabled the block of a selected Internet Control Message Protocol (ICMP) message. ICMP messages are either information requests or created as a reply to information requests or in error conditions.

  • Disable ICMP blocks in a zone
 firewall-cmd [--zone=<zone>] --remove-icmp-block=<icmptype>
  • Query ICMP blocks in a zone
 firewall-cmd [--zone=<zone>] --query-icmp-block=<icmptype>

This command returns if it is enabled, there is no output.

  • Example: Block echo-reply messages in the public zone:
 firewall-cmd --zone=public --add-icmp-block=echo-reply
  • Enable port forwarding or port mapping in a zone
 firewall-cmd [--zone=<zone>] --add-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }

The port is either mapped to the same port on another host or to another port on the same host or to another port on another host. The port can be a singe port <port> or a port range <port>-<port>. The protocol is either tcp or udp. toport is either port <port> or a port range <port>-<port>. toaddr is an IPv4 address. Port forwarding is IPv4 only because of kernel limitations.

  • Disable port forwarding or port mapping in a zone
 firewall-cmd [--zone=<zone>] --remove-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }
  • Query port forwarding or port mapping in a zone
 firewall-cmd [--zone=<zone>] --query-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }

This command returns if it is enabled, there is no output.

  • Example: Forward ssh to host 127.0.0.2 in the home zone
 firewall-cmd --zone=home --add-forward-port=port=22:proto=tcp:toaddr=127.0.0.2

处理永久区域

The permanent options are not affecting runtime directly. These options are only available after a reload or restart. To have runtime and permanent setting, you need to supply both. The --permanent option needs to be the first option for all permanent calls.

  • Get a list of supported permanent services
 firewall-cmd --permanent --get-services
  • Get a list of supported permanent icmptypes
 firewall-cmd --permanent --get-icmptypes
  • Get a list of supported permanent zones
 firewall-cmd --permanent --get-zones
  • Enable a service in a zone
 firewall-cmd --permanent [--zone=<zone>] --add-service=<service>

This enables the service in the zone permanently. If the zone option is omitted, the default zone is used.

  • Disable a service in a zone
 firewall-cmd --permanent [--zone=<zone>] --remove-service=<service>
  • Query if a service is enabled in a zone
 firewall-cmd --permanent [--zone=<zone>] --query-service=<service>

This command returns if it is enabled, there is no output.

  • Example: Enable service ipp-client permanently in the home zone
 firewall-cmd --permanent --zone=home --add-service=ipp-client
  • Enable a port and protocol combination permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --add-port=<port>[-<port>]/<protocol>
  • Disable a port and protocol combination permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --remove-port=<port>[-<port>]/<protocol>
  • Query if a port and protocol combination is enabled permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --query-port=<port>[-<port>]/<protocol>

This command returns if it is enabled, there is no output.

  • Example: Enable port 443/tcp for https permanently in the home zone
 firewall-cmd --permanent --zone=home --add-port=443/tcp
  • Enable masquerading permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --add-masquerade

This enables masquerading for the zone. The addresses of a private network are mapped to and hidden behind a public IP address. This is a form of address translation and mostly used in routers. Masquerading is IPv4 only because of kernel limitations.

  • Disable masquerading permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --remove-masquerade
  • Query masquerading permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --query-masquerade

This command returns if it is enabled, there is no output.

  • Enable ICMP blocks permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --add-icmp-block=<icmptype>

This enabled the block of a selected Internet Control Message Protocol (ICMP) message. ICMP messages are either information requests or created as a reply to information requests or in error conditions.

  • Disable ICMP blocks permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --remove-icmp-block=<icmptype>
  • Query ICMP blocks permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --query-icmp-block=<icmptype>

This command returns if it is enabled, there is no output.

  • Example: Block echo-reply messages in the public zone:
 firewall-cmd --permanent --zone=public --add-icmp-block=echo-reply
  • Enable port forwarding or port mapping permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --add-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }

The port is either mapped to the same port on another host or to another port on the same host or to another port on another host. The port can be a singe port <port> or a port range <port>-<port>. The protocol is either tcp or udp. toport is either port <port> or a port range <port>-<port>. toaddr is an IPv4 address. Port forwarding is IPv4 only because of kernel limitations.

  • Disable port forwarding or port mapping permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --remove-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }
  • Query port forwarding or port mapping permanently in a zone
 firewall-cmd --permanent [--zone=<zone>] --query-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }

This command returns if it is enabled, there is no output.

  • Example: Forward ssh to host 127.0.0.2 in the home zone
 firewall-cmd --permanent --zone=home --add-forward-port=port=22:proto=tcp:toaddr=127.0.0.2

直接选项

The direct options are mostly for services and applications to be able to add custom rules. The rules are not saved and have to get resubmitted after reload or restart. The arguments <args> of the passthrough option are the same as the corresponding iptables, ip6tables and ebtables arguments.

The --direct option needs to be the first option for all direct options.

  • Pass a command through to the firewall. <args> can be all iptables, ip6tables and ebtables command line arguments
 firewall-cmd --direct --passthrough { ipv4 | ipv6 | eb } <args>
  • Add a new chain <chain> to a table <table>.
 firewall-cmd --direct --add-chain { ipv4 | ipv6 | eb } <table> <chain>
  • Remove a chain with name <chain> from table <table>.
 firewall-cmd --direct --remove-chain { ipv4 | ipv6 | eb } <table> <chain>
  • Query if a chain with name <chain> exists in table <table>. Returns 0 if true, 1 otherwise.
 firewall-cmd --direct --query-chain { ipv4 | ipv6 | eb } <table> <chain>

This command returns if it is enabled, there is no output.

  • Get all chains added to table <table> as a space separated list.
 firewall-cmd --direct --get-chains { ipv4 | ipv6 | eb } <table>
  • Add a rule with the arguments <args> to chain <chain> in table <table> with priority <priority>.
 firewall-cmd --direct --add-rule { ipv4 | ipv6 | eb } <table> <chain> <priority> <args>
  • Remove a rule with the arguments <args> from chain <chain> in table <table>.
 firewall-cmd --direct --remove-rule { ipv4 | ipv6 | eb } <table> <chain> <args>
  • Query if a rule with the arguments <args> exists in chain <chain> in table <table>. Returns 0 if true, 1 otherwise.
 firewall-cmd --direct --query-rule { ipv4 | ipv6 | eb } <table> <chain> <args>

This command returns if it is enabled, there is no output.

  • Get all rules added to chain <chain> in table <table> as a newline separated list of arguments.
 firewall-cmd --direct --get-rules { ipv4 | ipv6 | eb } <table> <chain>

当前的 firewalld 特性

D-BUS 接口

D-BUS 接口提供防火墙状态的信息,使防火墙的启用、停用或查询设置成为可能。

区域

网络或者防火墙区域定义了连接的可信程度。firewalld 提供了几种预定义的区域。区域配置选项和通用配置信息可以在firewall.zone(5)的手册里查到。

服务

服务可以是一系列本读端口、目的以及附加信息,也可以是服务启动时自动增加的防火墙助手模块。预定义服务的使用使启用和禁用对服务的访问变得更加简单。服务配置选项和通用文件信息在 firewalld.service(5) 手册里有描述。

ICMP 类型

Internet 控制报文协议 (ICMP) 被用以交换报文和互联网协议 (IP) 的错误报文。在 firewalld 中可以使用 ICMP 类型来限制报文交换。 ICMP 类型配置选项和通用文件信息可以参阅 firewalld.icmptype(5) 手册。

直接接口

直接接口主要用于服务或者应用程序增加特定的防火墙规则。这些规则并非永久有效,并且在收到 firewalld 通过 D-Bus 传递的启动、重启、重载信号后需要重新应用。

运行时配置

运行时配置并非永久有效,在重新加载时可以被恢复,而系统或者服务重启、停止时,这些选项将会丢失。

永久配置

永久配置存储在配置文件种,每次机器重启或者服务重启、重新加载时将自动恢复。

托盘小程序

托盘小程序 firewall-applet 为用户显示防火墙状态和存在的问题。它也可以用来配置用户允许修改的设置。

图形化配置工具

firewall daemon 主要的配置工具是 firewall-config 。它支持防火墙的所有特性(除了由服务/应用程序增加规则使用的直接接口)。 管理员也可以用它来改变系统或用户策略。

命令行客户端

firewall-cmd 是命令行下提供大部分图形工具配置特性的工具。

对于 ebtables 的支持

要满足 libvirt daemon 的全部需求,在内核 netfilter 级上防止 ip*tables 和 ebtables 间访问问题,ebtables 支持是需要的。由于这些命令是访问相同结构的,因而不能同时使用。

/usr/lib/firewalld 中的默认/备用配置

该目录包含了由 firewalld 提供的默认以及备用的 ICMP 类型、服务、区域配置。由 firewalld 软件包提供的这些文件不能被修改,即使修改也会随着 firewalld 软件包的更新被重置。 其他的 ICMP 类型、服务、区域配置可以通过软件包或者创建文件的方式提供。

/etc/firewalld 中的系统配置设置

存储在此的系统或者用户配置文件可以是系统管理员通过配置接口定制的,也可以是手动定制的。这些文件将重载默认配置文件。

为了手动修改预定义的 icmp 类型,区域或者服务,从默认配置目录将配置拷贝到响应的系统配置五年级目录,然后根据需求进行修改。

不可变区域不能被重载,因为这些区域不能被修改。如果你加载了有默认和备用配置的区域,在 /etc/firewalld 下的对应文件将被重命名为 <file>.old 然后启用备用配置。

正在开发的特性

富语言

富语言特性提供了一种不需要了解iptables语法的通过高级语言配置复杂 IPv4 和 IPv6 防火墙规则的机制。

Fedora 19 提供了带有 D-Bus 和命令行支持的富语言特性第2个里程碑版本。第3个里程碑版本也将提供对于图形界面 firewall-config 的支持。

对于此特性的更多信息,请参阅: firewalld Rich Language

锁定

锁定特性为 firewalld 增加了锁定本地应用或者服务配置的简单配置方式。它是一种轻量级的应用程序策略。

Fedora 19 提供了锁定特性的第二个里程碑版本,带有 D-Bus 和命令行支持。第3个里程碑版本也将提供图形界面 firewall-config 下的支持。

更多信息请参阅: firewalld Lockdown

永久直接规则

这项特性处于早期状态。它将能够提供保存直接规则和直接链的功能。通过规则不属于该特性。更多关于直接规则的信息请参阅Direct options

从 ip*tables 和 ebtables 服务迁移

这项特性处于早期状态。它将尽可能提供由iptables,ip6tables 和 ebtables 服务配置转换为永久直接规则的脚本。此特性在由firewalld提供的直接链集成方面可能存在局限性。

此特性将需要大量复杂防火墙配置的迁移测试。

计划和提议功能

防火墙抽象模型

在 ip*tables 和 ebtables 防火墙规则之上添加抽象层使添加规则更简单和直观。要抽象层功能强大,但同时又不能复杂,并不是一项简单的任务。为此,不得不开发一种防火墙语言。使防火墙规则拥有固定的位置,可以查询端口的访问状态、访问策略等普通信息和一些其他可能的防火墙特性。

对于 conntrack 的支持

要终止禁用特性已确立的连接需要 conntrack 。不过,一些情况下终止连接可能是不好的,如:为建立有限时间内的连续性外部连接而启用的防火墙服务。

用户交互模型

这是防火墙中用户或者管理员可以启用的一种特殊模式。应用程序所有要更改防火墙的请求将定向给用户知晓,以便确认和否认。为一个连接的授权设置一个时间限制并限制其所连主机、网络或连接是可行的。配置可以保存以便将来不需通知便可应用相同行为。 该模式的另一个特性是管理和应用程序发起的请求具有相同功能的预选服务和端口的外部链接尝试。服务和端口的限制也会限制发送给用户的请求数量。

用户策略支持

管理员可以规定哪些用户可以使用用户交互模式和限制防火墙可用特性。

端口元数据信息(由 Lennart Poettering 提议)

拥有一个端口独立的元数据信息是很好的。当前对 /etc/services 的端口和协议静态分配模型不是个好的解决方案,也没有反映当前使用情况。应用程序或服务的端口是动态的,因而端口本身并不能描述使用情况。

元数据信息可以用来为防火墙制定简单的规则。下面是一些例子:

 允许外部访问文件共享应用程序或服务
 允许外部访问音乐共享应用程序或服务
 允许外部访问全部共享应用程序或服务
 允许外部访问 torrent 文件共享应用程序或服务
 允许外部访问 http 网络服务

这里的元数据信息不只有特定应用程序,还可以是一组使用情况。例如:组“全部共享”或者组“文件共享”可以对应于全部共享或文件共享程序(如:torrent 文件共享)。这些只是例子,因而,可能并没有实际用处。

这里是在防火墙中获取元数据信息的两种可能途径:

第一种是添加到 netfilter (内核空间)。好处是每个人都可以使用它,但也有一定使用限制。还要考虑用户或系统空间的具体信息,所有这些都需要在内核层面实现。

第二种是添加到 firewall daemon 中。这些抽象的规则可以和具体信息(如:网络连接可信级、作为具体个人/主机要分享的用户描述、管理员禁止完全共享的应归则等)一起使用。

第二种解决方案的好处是不需要为有新的元数据组和纳入改变(可信级、用户偏好或管理员规则等等)重新编译内核。这些抽象规则的添加使得 firewall daemon 更加自由。即使是新的安全级也不需要更新内核即可轻松添加。


sysctld

现在仍有 sysctl 设置没有正确应用。一个例子是,在 rc.sysinit 正运行时,而提供设置的模块在启动时没有装载或者重新装载该模块时会发生问题。

另一个例子是 net.ipv4.ip_forward ,防火墙设置、libvirt 和用户/管理员更改都需要它。如果有两个应用程序或守护进程只在需要时开启 ip_forwarding ,之后可能其中一个在不知道的情况下关掉服务,而另一个正需要它,此时就不得不重启它。

sysctl daemon 可以通过对设置使用内部计数来解决上面的问题。此时,当之前请求者不再需要时,它就会再次回到之前的设置状态或者是直接关闭它。


防火墙规则

netfilter 防火墙总是容易受到规则顺序的影响,因为一条规则在链中没有固定的位置。在一条规则之前添加或者删除规则都会改变此规则的位置。 在静态防火墙模型中,改变防火墙就是重建一个干净和完善的防火墙设置,且受限于 system-config-firewall / lokkit 直接支持的功能。也没有整合其他应用程序创建防火墙规则,且如果自定义规则文件功能没在使用 s-c-fw / lokkit 就不知道它们。默认链通常也没有安全的方式添加或删除规则而不影响其他规则。

动态防火墙有附加的防火墙功能链。这些特殊的链按照已定义的顺序进行调用,因而向链中添加规则将不会干扰先前调用的拒绝和丢弃规则。从而利于创建更为合理完善的防火墙配置。

下面是一些由守护进程创建的规则,过滤列表中启用了在公共区域对 ssh , mdns 和 ipp-client 的支持:

 *filter
 :INPUT ACCEPT [0:0]
 :FORWARD ACCEPT [0:0]
 :OUTPUT ACCEPT [0:0]
 :FORWARD_ZONES - [0:0]
 :FORWARD_direct - [0:0]
 :INPUT_ZONES - [0:0]
 :INPUT_direct - [0:0]
 :IN_ZONE_public - [0:0]
 :IN_ZONE_public_allow - [0:0]
 :IN_ZONE_public_deny - [0:0]
 :OUTPUT_direct - [0:0]
 -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
 -A INPUT -i lo -j ACCEPT
 -A INPUT -j INPUT_direct
 -A INPUT -j INPUT_ZONES
 -A INPUT -p icmp -j ACCEPT
 -A INPUT -j REJECT --reject-with icmp-host-prohibited
 -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
 -A FORWARD -i lo -j ACCEPT
 -A FORWARD -j FORWARD_direct
 -A FORWARD -j FORWARD_ZONES
 -A FORWARD -p icmp -j ACCEPT
 -A FORWARD -j REJECT --reject-with icmp-host-prohibited
 -A OUTPUT -j OUTPUT_direct
 -A IN_ZONE_public -j IN_ZONE_public_deny
 -A IN_ZONE_public -j IN_ZONE_public_allow
 -A IN_ZONE_public_allow -p tcp -m tcp --dport 22 -m conntrack --ctstate NEW -j ACCEPT
 -A IN_ZONE_public_allow -d 224.0.0.251/32 -p udp -m udp --dport 5353 -m conntrack --ctstate NEW -j ACCEPT
 -A IN_ZONE_public_allow -p udp -m udp --dport 631 -m conntrack --ctstate NEW -j ACCEPT

使用 deny/allow 模型来构建一个清晰行为(最好没有冲突规则)。例如: ICMP 块将进入 IN_ZONE_public_deny 链(如果为公共区域设置了的话),并将在 IN_ZONE_public_allow 链之前处理。

该模型使得在不干扰其他块的情况下向一个具体块添加或删除规则而变得更加容易。