LoginSignup
22
27

More than 3 years have passed since last update.

firewalld初心者のメモ

Last updated at Posted at 2016-01-26

これはfirewalld初心者の学習メモです.

  • firewalldではNIC単位で火壁を設定する.
  • デフォルト値から変更した設定は/etc/firewalld内のxmlファイルに書かれる.
  • ユーザー設定のxmlに異常があるとき/usr/lib/firewalld内のデフォルト設定が使用される.
  • デフォルトでeth0はpublicゾーンが設定されている.

Kobito.LhFicm.png
フィルタリングイメージ図

Commands

現在の設定をみる
firewall-cmd --zone=public --list-all

service sshをpublicから外す
firewall-cmd --zone=public --remove-service=ssh --permanent

ping応答しない
firewall-cmd --zone=public --add-icmp-block={echo-request,echo-reply,timestamp-reply,timestamp-request} --permanent

複数の条件でフィルタリング
firewall-cmd --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.0.0/24" service name="ssh" accept' --permanent

firewall-cmd --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.0.0/24" service name="samba" accept' --permanent

firewall-cmd --zone=public --add-rich-rule='rule family="ipv4" source address="192.168.0.0/24" port port="22" protocol="tcp" accept'

設定を反映する
firewall-cmd --reload

NICのゾーン変更
firewall-cmd --zone=work --change-interface=eth0 --permanent

  • デフォルトゾーン(public)設定を操作するするときは"--zone=public"は省略可能
  • "--permanent"を付けなければ即時に設定が反映されるが再起動もしくは"--reload"した時には設定から外れる

IPマスカレード

firewall-cmd --zone=public --add-masquerade --permanent
firewall-cmd --zone=trusted --add-masquerade --permanent
firewall-cmd --permanent --direct --add-rule ipv4 nat POSTROUTING 0 -o eth0 -j MASQUERADE
firewall-cmd --permanent --direct --add-rule ipv4 filter FORWARD 0 -i tun0 -o eth0 -j ACCEPT
firewall-cmd --permanent --direct --add-rule ipv4 filter FORWARD 0 -i eth0 -o tun0 -m state --state RELATED,ESTABLISHED -j ACCEPT

NFQUEUE

firewall-cmd --zone=public --permanent --direct --add-rule ipv4 filter OUTPUT 0 -d 8.8.8.8 -j NFQUEUE --queue-num 1

firewall-cmd --zone=public --permanent --direct --add-rule ipv4 filter FORWARD 0 -i enp5s0 -j NFQUEUE --queue-num 1

ダイレクトルールの一覧表示

firewall-cmd --direct --get-all-rules

ssh ポート番号変更

cp /usr/lib/firewalld/services/ssh.xml /etc/firewalld/services/ssh.xml
vi /etc/firewalld/services/ssh.xml

参考文献

22
27
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
22
27