LoginSignup
5

More than 5 years have passed since last update.

centos7でfirewalldを使い、日本国内のhttpアクセスのみ許可する方法

Last updated at Posted at 2017-04-17

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/

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5