centos7でfirewalldを使い、日本国内のhttpアクセスのみ許可する方法を紹介します。
環境
centos7
コマンド
# wget https://ipv4.fetus.jp/jp.txt
# firewall-cmd --permanent --new-ipset=jp --type=hash:net
# firewall-cmd --permanent --ipset=jp --add-entries-from-file=jp.txt
# firewall-cmd --permanent --zone=external --add-source=ipset:jp
# firewall-cmd --permanent --zone=external --add-service=http
# firewall-cmd --reload
はじめに日本のIPリストを取得し、それをjpという変数に格納します。
ipset:jpに該当したアクセスをexternalの定義に飛ばし、
externalの中で、httpのみ許可する、という設定を行っています。
さらに、定期的にIPリストを更新できるとなお良いと思います。
参考
以下参考にさせて頂きました。
https://www.kunitaya.info/memo/firewalld%E3%81%A7ipset%E3%82%92%E4%BD%BF%E3%81%86%E6%96%B9%E6%B3%95/
https://seinolab.jp/firewalld-example-2/