LoginSignup
24
29

More than 5 years have passed since last update.

[CentOS] firewalldで特定のサービスを特定のIPアドレスに対して許可する

Posted at

firewalld?

CentOS7のfirewalldをまじめに使うはじめの一歩(systemdも少し)
が詳しいと思います。

やりたいこと

デフォルトのzone(public)のルールはそのままに、特定のサービス(今回はMySQL)を特定のIPアドレスに対してのみ許可したい

方法

カスタムのzoneを作成してあげることで実現します

MySQLを特定のIPに許可してあげる.sh
firewall-cmd --permanent --new-zone=mysql # --permanentオプション必須 zone名は任意
firewall-cmd --reload

firewall-cmd --permanent --zone=mysql --set-target=ACCEPT
firewall-cmd --permanent --zone=mysql --add-service=mysql
firewall-cmd --permanent --zone=mysql --add-source=192.168.0.0/24 # 許可するソース
firewall-cmd --reload

firewall-cmd --get-active-zones # 追加したzone(+ソース)が表示されればOK

--set-targetってのを設定するのに苦労しました

参考

http://www.firewalld.org/documentation/man-pages/firewall-cmd.html
http://serverfault.com/questions/684602/how-to-open-port-for-a-specific-ip-address-with-firewall-cmd-on-centos/684739#684739

24
29
0

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
24
29