SSブログ
Linux(Network/その他) ブログトップ

うーん…firewalld…。。。 [Linux(Network/その他)]

 CentOS7 をいろいろお試し中。
 firewalldの設定に盛大に躓く。

 まず、NICが複数ある環境。そのうちの一つはグローバルなネットワークに接続があるので、環境設定が完了するまで外部からのアクセスは全て拒否したい。しかし、中から外へのアクセスは通したい。(yumしたりするし。)
 …ということは、「block」ゾーンを適用すれば良い。残りのNICは内部のネットワークなので、だいたい自由にアクセスを通したい。(今のところはまだsshだけあればいいのだけど。)

[root@nana ~]# firewall-cmd --get-active-zones
public
  interfaces: ens32 ens33 ens34


 初期状態ではこのような状態。このうち、ens34をblockゾーンに変更したい。
 google先生で検索した結果、

[root@nana ~]# firewall-cmd --zone=block --change-interface=ens34
success
[root@nana ~]# firewall-cmd --get-active-zones
public
  interfaces: ens32 ens33
block
  interfaces: ens34


 これでゾーンの変更は出来る。ただしまだこのままでは「永続化」されないのでrebootするとこの設定は消えて無くなってしまうとのこと。このため、「--permanent」オプションを付けて同じコマンドを再度実行する必要があるらしいということは判った。なお、この--permanentオプションはコマンドの直後、全てのオプション・引数の先頭に付ける必要があるらしい。
 というわけで…

[root@nana ~]# firewall-cmd --permanent --zone=block --change-interface=ens34
success
[root@nana ~]# firewall-cmd --reload
success
[root@nana ~]# firewall-cmd --get-active-zones
public
  interfaces: ens32 ens33
block
  interfaces: ens34


 reloadして再度確認してみる。ens34は最初のコマンドで動的にblockゾーンに変更されているので、特に変化は無い。
 これでOKなのかと思ってrebootしたりすると…

[root@nana ~]# reboot
Connection to nana closed by remote host.
Connection to nana closed.
[root@lelouch ~]# slogin nana
Last login: Thu Sep  4 10:52:21 2014 from lelouch.office.**********.co.jp
[root@nana ~]# firewall-cmd --get-active-zones
public
  interfaces: ens32 ens33 ens34


 エー?

 落ち着け。manページを再確認するんだ…。だいたいこう言うのはどこかチョンボしているに違いない。
 というわけで、 man firewall-cmd してみたら案の定!!

(略)
       [--permanent] [--zone=zone] --add-interface=interface
           Bind interface interface to zone zone. If zone is omitted, default zone will be used.

       [--zone=zone] --change-interface=interface
           Change zone the interface interface is bound to to zone zone. If zone is omitted, default zone will be used. If old and new zone are the
           same, the call will be ignored without an error. If the interface has not been bound to a zone before, it will behave like
           --add-interface.

       [--permanent] [--zone=zone] --query-interface=interface
           Query whether interface interface is bound to zone zone. Returns 0 if true, 1 otherwise.

       [--permanent] [--zone=zone] --remove-interface=interface
           Remove binding of interface interface from zone zone. If zone is omitted, default zone will be used.
(略)


 --change-interface オプションでは --permanent オプションが使えないっぽい?
 HAHAHA!! そりゃーうまくいかないよな!! (successとか出すなよな!!)

 これを見る限りでは、ens34インタフェースをpublicからblockに変更するなら、removeしてaddすればよさそう?

 …というわけで、試して見た。

 まずは永続化しないでコマンド実行

[root@nana ~]# firewall-cmd --zone=public --remove-interface=ens34
success
[root@nana ~]# firewall-cmd --zone=block --add-interface=ens34
success
[root@nana ~]# firewall-cmd --get-active-zones
public
  interfaces: ens32 ens33
block
  interfaces: ens34


 うむ。ここまではOK。これを永続化したいのです。

[root@nana ~]# firewall-cmd --permanent --zone=public --remove-interface=ens34
success
[root@nana ~]# firewall-cmd --permanent --zone=block --add-interface=ens34
success
[root@nana ~]# firewall-cmd --reload
success
[root@nana ~]# firewall-cmd --get-active-zones
public
  interfaces: ens32 ens33
block
  interfaces: ens34


 で、レッツ・再起動!!

[root@nana ~]# reboot
Connection to nana closed by remote host.
Connection to nana closed.
[root@lelouch ~]# slogin nana
Last login: Thu Sep  4 11:00:01 2014 from lelouch.office.**********.co.jp
[root@nana ~]# firewall-cmd --get-active-zones
public
  interfaces: ens32 ens33 ens34


 …。
 うそつきーーーーー!!!!!

 ちなみに、/etc/sysconfig/network-scripts/ifcfg-* に、

ZONE=block


 と書けば、再起動後そのゾーンに所属した状態で起動してくることは確認出来ている。

[root@nana ~]# firewall-cmd --get-active-zones
public
  interfaces: ens32 ens33 ens34
[root@nana ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens34
[root@nana ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens34
TYPE=Ethernet
BOOTPROTO=none
(略)
ZONE=block
[root@nana ~]# reboot
Connection to nana closed by remote host.
Connection to nana closed.
[root@lelouch ~]# slogin nana
Last login: Thu Sep  4 11:15:34 2014 from lelouch.office.**********.co.jp
[root@nana ~]# firewall-cmd --get-active-zones
public
  interfaces: ens32 ens33
block
  interfaces: ens34


 しかし、これじゃあそもそもfirewalldを使う意味が全く無いよね!!!

 もしかすると、blockとかdropとかこの辺のゾーンはそもそも永続化できないゾーンなのかもしれない?
 試しに、ens34をexternalゾーンに所属を変更してみて永続化し、rebootしてどうなるか確認してみよう。

[root@nana ~]# firewall-cmd --get-active-zones
public
  interfaces: ens32 ens33 ens34
[root@nana ~]# firewall-cmd --zone=public --remove-interface=ens34
success
[root@nana ~]# firewall-cmd --zone=external --add-interface=ens34
success
[root@nana ~]# firewall-cmd --get-active-zones
external
  interfaces: ens34
public
  interfaces: ens32 ens33


 で、永続化。

[root@nana ~]# firewall-cmd --permanent --zone=public --remove-interface=ens34
success
[root@nana ~]# firewall-cmd --permanent --zone=external --add-interface=ens34
Error: ZONE_CONFLICT


 おや?

[root@nana ~]#  firewall-cmd --zone=external --list-interfaces
[root@nana ~]#  firewall-cmd --zone=block --list-interfaces
[root@nana ~]#  firewall-cmd --zone=public --list-interfaces
ens32 ens33 ens34


 もう、何が何やら…。。。

 ひとまず、ifcfg-ens*に ZONE=block と書いて回避することに…orz

 なにか違うのだろうけど何が違うのやら情報も少ないしさっぱりポンですわもう。

Linux(Network/その他) ブログトップ

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。