てくなべ (tekunabe)

ansible / network automation / 学習メモ

firewalld の Intra Zone Forwarding の機能有無やデフォルト値

はじめに

firewalld の firewall-cmd --list-all の結果で、forward という項目がある環境とない環境があることに気が付きました。forward-ports とはまた別物です。

0.9.0で導入された、Intra Zone Forwarding という機能のものによるようです。

気になったので、いくつか別途用意して表示のされ方などを確認しました。

まとめ

先にまとめです。

RHEL firewalld バージョン Intra Zone Forwarding 機能有無 Intra Zone Forwarding デフォルト設定
8.4 0.8.2 なし -
8.4 0.9.3 あり 無効
9.0 Beta 1.0.0 あり 有効

firewalld 0.8.2 on RHEL 8.4

Red Hat Enterprise Linux 8.4 を、GUIがないサーバーとしてインストールした環境です。

[admin@localhost ~]$ cat /etc/redhat-release 
Red Hat Enterprise Linux release 8.4 (Ootpa)

バージョン確認

firewalld 0.8.2 がインストールされています。

[admin@localhost ~]$ sudo dnf list --installed | grep -i firewalld
firewalld.noarch                              0.8.2-6.el8                                 @anaconda 
firewalld-filesystem.noarch                   0.8.2-6.el8                                 @anaconda 

firewall-cmd --list-all

firewall-cmd --list-all コマンドの結果は以下のとおりです。forward という項目はありません、

[admin@localhost ~]$ sudo firewall-cmd --list-all 
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens192
  sources: 
  services: cockpit dhcpv6-client ssh
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

firewalld 0.9.3 on RHEL 8.4

続いて、firewalld アップグレードした環境で試します。

firewalld のアップグレード

[admin@localhost ~]$ sudo dnf upgrade firewalld
Updating Subscription Management repositories.
Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs)                       33 MB/s |  39 MB     00:01    
Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)                          35 MB/s |  45 MB     00:01    
Dependencies resolved.
==============================================================================================================
 Package                     Architecture  Version                 Repository                            Size
==============================================================================================================
Upgrading:
 firewalld                   noarch        0.9.3-7.el8_5.1         rhel-8-for-x86_64-baseos-rpms        502 k
 firewalld-filesystem        noarch        0.9.3-7.el8_5.1         rhel-8-for-x86_64-baseos-rpms         77 k
 python3-firewall            noarch        0.9.3-7.el8_5.1         rhel-8-for-x86_64-baseos-rpms        433 k

Transaction Summary
==============================================================================================================
Upgrade  3 Packages

Total download size: 1.0 M
Is this ok [y/N]: y
...()...

バージョン確認

0.9.3 になりました。

[admin@localhost ~]$ sudo dnf list --installed | grep -i firewalld
firewalld.noarch                              0.9.3-7.el8_5.1                             @rhel-8-for-x86_64-baseos-rpms
firewalld-filesystem.noarch                   0.9.3-7.el8_5.1                             @rhel-8-for-x86_64-baseos-rpms

firewall-cmd --list-all

firewall-cmd --list-all コマンドの結果を見ると foward: no という項目が追加されました。

[admin@localhost ~]$ sudo firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens192
  sources: 
  services: cockpit dhcpv6-client ssh
  ports: 
  protocols: 
  forward: no
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

これが firewalld 0.9.0で導入された、Intra Zone Forwarding という機能のものによるようです。

この時点では、デフォルトでオフです。(Intra Zone Forwarding 説明ページから)

By default, all currently shipped zone definitions and user created zones have forward disabled.

設定を変更してみる (有効化)

firewall-cmd コマンドのヘルプを見ると、以下オプションが増えていました。

...(略)...
  --add-forward        Enable forwarding of packets between interfaces and
                       sources in a zone [P] [Z] [T]
  --remove-forward     Disable forwarding of packets between interfaces and
                       sources in a zone [P] [Z]
  --query-forward      Return whether forwarding of packets between interfaces
                       and sources has been enabled for a zone [P] [Z]
...(略)...

軽く試します。

[admin@localhost ~]$ sudo firewall-cmd --add-forward --permanent
success
[admin@localhost ~]$ sudo firewall-cmd --reload
success

変更後、firewall-cmd --list-all を見ると forward: yes になりました。

[admin@localhost ~]$ sudo firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens192
  sources: 
  services: cockpit dhcpv6-client ssh
  ports: 
  protocols: 
  forward: yes
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

一応、/etc/firewalld/zones/public.xml ファイルを見ます。<forward/> がついてました。

[admin@localhost ~]$ sudo cat /etc/firewalld/zones/public.xml
<?xml version="1.0" encoding="utf-8"?>
<zone>
  <short>Public</short>
  <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
  <service name="ssh"/>
  <service name="dhcpv6-client"/>
  <service name="cockpit"/>
  <forward/>
</zone>

設定を変更してみる (無効化)

--remove-forward で元に戻します。

[admin@localhost ~]$ sudo firewall-cmd --remove-forward --permanent
success
[admin@localhost ~]$ sudo firewall-cmd --reload
success

forward: no に戻りました。

[admin@localhost ~]$ sudo firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens192
  sources: 
  services: cockpit dhcpv6-client ssh
  ports: 
  protocols: 
  forward: yes
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

/etc/firewalld/zones/public.xml からは <forward/> が消えました。

[admin@localhost ~]$ sudo cat /etc/firewalld/zones/public.xml
<?xml version="1.0" encoding="utf-8"?>
<zone>
  <short>Public</short>
  <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
  <service name="ssh"/>
  <service name="dhcpv6-client"/>
  <service name="cockpit"/>
</zone>

1.0.0 on RHEL 9.0 Beta

今度は別に構築した、Red Hat Enterprise Linux 9.0 Beta の環境で試します。

[admin@localhost ~]$ cat /etc/redhat-release 
Red Hat Enterprise Linux release 9.0 Beta (Plow)

バージョン確認

firewalld 1.0.0 がインストールされています。

[admin@localhost ~]$ sudo dnf list --installed | grep -i firewalld
firewalld.noarch                              1.0.0-3.el9_b                             @anaconda 
firewalld-filesystem.noarch                   1.0.0-3.el9_b                             @anaconda 

firewall-cmd --list-all

firewall-cmd --list-all コマンドの結果を確認します。

[admin@localhost ~]$ sudo firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens192
  sources: 
  services: cockpit dhcpv6-client ssh
  ports: 
  protocols: 
  forward: yes
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

おっと、デフォルトで forward: yes でした。

firewalld のリリースノートとたどってみると、ちょうど 1.0.0 で Intra Zone Forwarding がデフォルトで有効になったようです。

Intra-zone forwarding by default

github.com

firewalld.org

なお、微妙に別件のようですが、Red Hat Enterprise Linux 9.0 Beta のリリースノートの Networking には

Changed behavior in firewalld when transmitting packets between zones

という記載がありました。

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9-beta/html/9.0_release_notes/new-features#enhancement_networking