概要
Ubuntu で ufw を利用して ping を拒否する機会があったのでメモ。
Ubuntu では ファイアウォールの設定は ufw を利用した方が良い。
ping のプロトコルは ICMP になる。
設定(IPv4)
「/etc/ufw/before.rules」に以下の設定をする。
-A ufw-before-input -p icmp --icmp-type destination-unreachable -j DROP
-A ufw-before-input -p icmp --icmp-type source-quench -j DROP
-A ufw-before-input -p icmp --icmp-type time-exceeded -j DROP
-A ufw-before-input -p icmp --icmp-type parameter-problem -j DROP
-A ufw-before-input -p icmp --icmp-type echo-request -j DROP
当然 ufw を有効にしておく必要がある。
sudo ufw enable
ファイルのパーミッションが不正だと警告が出るので、確認。
chown root:root /etc/ufw/before.rules
chmod 640 /etc/ufw/before.rules
設定(IPv6)
IPv6も設定するなら、「/etc/ufw/before6.rules」にも設定しないといけない模様。
ufwの有効化
当然 ufw を有効にしておく必要がある。
sudo ufw enable
ファイルのパーミッションが不正だと警告が出るので、確認。
chown root:root /etc/ufw/before6.rules
chmod 640 /etc/ufw/before6.rules
まとめ
ufw のコマンド経由では設定できないので、設定ファイルを編集する必要がある。
2012/10/13公開後追記:
Ubuntu 12.04 でこの設定をすると再起動時に「ERROR: problem running ufw-init」エラーが発生して、ufw が有効にならない様子。
公式説明にある、「Enable PING」を再度参考にして設定したが、変化しない。
「/lib/ufw/ufw-init restart」すると、rules のエラーが表示される。
以下でも同じような現象が発生している。
UFW ERROR: problem running ufw-init
2012/10/13夜追加
上記のエラーは単にfilterの記述忘れだった。
*filter
:ufw-before-input - [0:0]
:ufw-before-output - [0:0]
:ufw-before-forward - [0:0]
-A ufw-before-input -p icmp --icmp-type destination-unreachable -j DROP
-A ufw-before-input -p icmp --icmp-type source-quench -j DROP
-A ufw-before-input -p icmp --icmp-type time-exceeded -j DROP
-A ufw-before-input -p icmp --icmp-type parameter-problem -j DROP
-A ufw-before-input -p icmp --icmp-type echo-request -j DROP
COMMIT