ipset を ipv6 に適用する手続き

January 17, 2020 – 3:28 pm

我がサーバ(OS:CentOS7)では、ipsetを用いて firewalldを運用している。

今回、ipv6に対してもipsetを適用可能にしたので、その設定手続きについてメモしておいた。

なお、ipset導入の手続きについては、既に「fierewalld で ipset を用いる手続きをメモしておいた」に記述しており、以下はipv6用のipsetを作成するための補足。


ipv6用ipsetの作成(セット名をtestipv6とする)

firewall-cmd --permanent --new-ipset=testipv6 --type=hash:net --option=family=inet6

ここで、ipv6用のipsetを作成するため –option=family=inet6 を追加する必要している。

これにより、設定ファイル testipv6.xmlが /etc/firewalld/ipset 配下に作られる。

testipv6.xml:

<?xml version="1.0" encoding="utf-8"?>
<ipset type="hash:net">
  <option name="family" value="inet6"/>
</ipset>

ipsetを適用するipv6アドレスを以下のように追加

firewall-cmd --permanent --ipset=testipv6 --add-entry=2600:1f14:b62::/48

ここで、2600:1f14:b62::/48は例示にすぎない。

上記のipv6アドレス追加を反映し、testipv6.xmlは次のように<entry> . </entry> 部にアドレスが追加される

testipv6.xml:

<?xml version="1.0" encoding="utf-8"?>
<ipset type="hash:net">
  <option name="family" value="inet6"/>
  <entry>2600:1f14:b62::/48</entry>
</ipset>

以下のコマンドで、ipset testipv6を firewalld のzone dropに登録する。これによりtestipv6に登録されているipv6アドレスをブロックすることになる

firewall-cmd --permanent --zone=drop --add-source=ipset:testipv6

設定ファイル/etc/firewalld/zone/drop.xmlに ipset testipv6が以下のように反映される。

drop.xml:

<?xml version="1.0" encoding="utf-8"?>
<zone target="DROP">
  <short>Drop</short>
  <description>Unsolicited incoming network packets are dropped. Incoming packets that are related to outgoing network connections are accepted. Outgoing network connections are allowed.</description>
  <source ipset="testipv6"/>
</zone>

以上の手続きを有効にするため、以下のコマンドを実行

firewall-cmd --reload

  
  


Post a Comment