そろそろfirewalldを使ってみようかな〜ということで、yaourt -S firewalld
してインストールして設定してみました。
やったことはzoneを新規に作って、source(192.168.11.0/24)をそこに割り当てて、サービス(sshとか)を許可したりということ。
まずはデフォルトゾーンの確認とhome zoneのssh設定を確認。デフォルトは自分で設定して、enp101s0をI/Fに設定済み。
[root@saga ~]# firewall-cmd --get-default-zone home [root@saga ~]# iptables -L | grep ssh ACCEPT tcp -- anywhere anywhere tcp dpt:ssh ctstate NEW
homenet zoneの作成
[root@saga ~]# firewall-cmd --permanent --new-zone=homenet success
設定変更したのでリロード
[root@saga ~]# firewall-cmd --reload success
作成したzoneの確認
[root@saga ~]# firewall-cmd --zone=homenet --list-all homenet interfaces: sources: services: ports: masquerade: no forward-ports: icmp-blocks: rich rules:
homenetにsourceを設定
[root@saga ~]# firewall-cmd --permanent --add-source=192.168.11.0/24 --zone=homenet success
homenetでsshを許可
[root@saga ~]# firewall-cmd --permanent --add-service=ssh --zone=homenet success
デフォルトのzoneをhomenetに変更
[root@saga ~]# firewall-cmd --set-default-zone=homenet success
home zoneに設定していたenp101s0をhomenetに変更。
[root@saga ~]# firewall-cmd --zone=homenet --change-interface=enp101s0 success
firewall-cmd --reload
してからiptable -L
で設定された内容を確認。
Chain IN_homenet_allow (1 references) target prot opt source destination ACCEPT tcp -- anywhere anywhere tcp dpt:ssh ctstate NEW
ssh brute force attack対策。60秒間に5回の試行が行われたら60秒間DROPする。IN_homenetが対象のchainで、後ろの[0-2]はruleの優先度。0はログを取っているだけなので、DROPするのは1のルール。0と1に引っかからなければ2のルールでアクセスできる。
[root@saga ~]# firewall-cmd --permanent --direct --add-rule ipv4 filter IN_homenet 0 -p tcp -m tcp --dport 22 -m recent --update --seconds 60 --hitcount 5 --rttl --name SSH --rsource -m comment --comment "SSH Brute-force protection" -j LOG --log-prefix "SSH_brute_force " success [root@saga ~]# firewall-cmd --permanent --direct --add-rule ipv4 filter IN_homenet 1 -p tcp -m tcp --dport 22 -m recent --update --seconds 60 --hitcount 5 --rttl --name SSH --rsource -m comment --comment "SSH Brute-force protection" -j DROP success [root@saga ~]# firewall-cmd --permanent --direct --add-rule ipv4 filter IN_homenet 2 -p tcp -m tcp --dport 22 -m state --state NEW -m recent --set --name SSH --rsource -m comment --comment "SSH Brute-force protection" -j ACCEPT success
いつもどおり、firewall-cmd --reload
してiptables
で確認。
Chain IN_homenet (2 references) target prot opt source destination LOG tcp -- anywhere anywhere tcp dpt:ssh recent: UPDATE seconds: 60 hit_count: 5 TTL-Match name: SSH side: source mask: 255.255.255.255 /* SSH Brute-force protection */ LOG level warning prefix "SSH_brute_force " DROP tcp -- anywhere anywhere tcp dpt:ssh recent: UPDATE seconds: 60 hit_count: 5 TTL-Match name: SSH side: source mask: 255.255.255.255 /* SSH Brute-force protection */ ACCEPT tcp -- anywhere anywhere tcp dpt:ssh state NEW recent: SET name: SSH side: source mask: 255.255.255.255 /* SSH Brute-force protection */
logはjournalctlで確認できます。
ちなみに、ssh brute force attack対策する理由は単に↓です。
firewallの機能でsshの総当り攻撃をブロックしたいって質問の答えで、portを変えろとか、パスワードを強力にしろってのは的外れな回答で、なんでしたいかって言ったら、うざいからブロックしたいんだよってことですよ。 #ググッて見つかった質問と回答を見ながら
— なんつってつっちゃった (@masami256) 2015, 5月 31
そもそもパスワードでのloginは許可してないしな > ssh
— なんつってつっちゃった (@masami256) 2015, 5月 31
ここまで設定してみた感想としては、iptablesで直接設定していくよりは良いかもな〜というところ。 まだ、設定方法をググって何をやってるのかを理解して設定していってるだけだけど。
今回参考にしたWebサイトはこちら
https://fedoraproject.org/wiki/FirewallD/jp
FirewallD: Adding Services and Direct Rules ~ IT Notes and Scribblings
RHEL7: How to mitigate HTTP attacks. - CertDepot
CentOS7(RHEL7) Firewalldの基礎の基礎 | LINUXの勉強ブログ
- 作者: 株式会社ハートビーツ,馬場俊彰
- 出版社/メーカー: 技術評論社
- 発売日: 2015/03/27
- メディア: 大型本
- この商品を含むブログ (1件) を見る