URAMIRAIKAN

1020のなれの果て (since 2005.6.19)

"firewalld"の一部の設定が反映されない?

 検証環境でCentOS7をルーターとして使うために設定していたときにハマりました。

 サーバにはeth0とeth1の2つのNICがあり、eth1でIPマスカレードを有効にするためfirewalldのゾーンを"external"に変更しました。
 firewalldを操作する"firewall-cmd"コマンドでは、永続的な変更をする際にはオプションに"--permanent"を付与するという認識だったので、

# firewall-cmd --change-interface=eth1 --zone=external --permanent

として実行したのですが、サーバを再起動したところ元に戻ってしまったのです。

 そんなことで、とりあえず調査したことのメモです。

 とりあえず切り分けのため、別のサーバに最小構成でCentOS7を入れました。その環境で"firewall-cmd"を実行します。

 まずは最初の状態。

# firewall-cmd --get-active-zone
public
interfaces: eth0 eth1
# firewall-cmd --get-default-zone
public

 続いてeth1のゾーンを"external"に変更します。

# firewall-cmd --change-interface=eth1 --zone=external
success
# firewall-cmd --get-active-zone
external
interfaces: eth1
public
interfaces: eth0

 最終的にこの状態にしたかったのですが、この設定はサーバを再起動すると消えてしまいます。
 そこで、設定を永続的にするために"--permanent"オプションを使います。

# firewall-cmd --get-active-zones
public
interfaces: eth0 eth1
# firewall-cmd --change-interface=eth1 --zone=external --permanent
success
# firewall-cmd --get-active-zones
public
interfaces: eth0 eth1
# firewall-cmd --reload
success
# firewall-cmd --get-active-zones
public
interfaces: eth0 eth1

 この時点では設定は反映されていません。firewalldをリロードしても同様でした。
 そこで、サーバをリブートして確認します。

# firewall-cmd --get-active-zones
external
interfaces: eth1
public
interfaces: eth0

 再起動後は設定が反映されていました。これは想定通りの動作です。

 しかし、もともと構築中だったサーバとは挙動が違うのが腑に落ちません。
 そこで環境を近づけるために"yum -y update"を実行し、その後で同じ事をやりました。

 すると、"--permanent"オプションをつけて実行した後に再起動してもゾーンの変更が反映されません。
 念のため、設定ファイル"/etc/firewalld/zones/external.xml"を確認しましたが、ファイルには"<interface name="eth1"/>"という記述があり、コマンドの結果が反映しているように見えます。

# firewall-cmd --get-active-zone
public
interfaces: eth0 eth1
# firewall-cmd --change-interface=eth1 --zone=external --permanent
success
# cat /etc/firewalld/zones/external.xml
<?xml version="1.0" encoding="utf-8"?> <zone> <short>External</short> <description>For use on external networks. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description> <interface name="eth1"/> <service name="ssh"/> <masquerade/> </zone>

 しかし、再起動してもeth1はデフォルトである"public"ゾーンのままです。

 他にやったことは割愛していますが、自分がやった限りだと最新のパッケージに問題があるように見えます(firewalldなのか、それ以外なのかまでは調べていませんが)。

# rpm -qi firewalld
Name : firewalld Version : 0.3.9 Release : 7.el7 Architecture: noarch Install Date: 2015年03月17日 14時04分50秒 Group : System Environment/Base Size : 2454832 License : GPLv2+ Signature : RSA/SHA256, 2014年07月04日 10時21分18秒, Key ID 24c6a8a7f4a80eb5 Source RPM : firewalld-0.3.9-7.el7.src.rpm Build Date : 2014年06月10日 16時19分26秒 Build Host : worker1.bsys.centos.org Relocations : (not relocatable) Packager : CentOS BuildSystem <http://bugs.centos.org> Vendor : CentOS URL : http://fedorahosted.org/firewalld Summary : A firewall daemon with D-BUS interface providing a dynamic firewall Description : firewalld is a firewall service daemon that provides a dynamic customizable firewall with a D-BUS interface.

 とりえあず原因の調査は後にして、この現象が起こることを前提に環境の構築を進めることにしました。

 ゾーンの設定はNetworkManagerからも設定することができます。

# nmcli conn show eth1 | grep zone
connection.zone: --
# nmcli conn mod eth1 connection.zone external
# nmcli conn show eth1 | grep zone
connection.zone: external
# firewall-cmd --get-active-zone
external
interfaces: eth1
public
interfaces: eth0

 この設定は(当然ですが)再起動後も維持されました。
 当面は、

  • 開放するサービス/ポート等のルール → firewall-cmd
  • ゾーンの設定 → NetworkManager

で分けてやっていこうと思います。

 まあ、本家のRHELは既に7.1が出ていますし、仮にパッケージ側の問題ならすぐに修正されるような気がしますが。