CONTENTS


Lastmodified 2023-10-27 (金) 16:00:05


ipfw

ipfw でフィルタリング

FreeBSD 12.1で ファイアウォール ( ipfw )の設定

ipfwでファイアーウォールを設定

FreeBSD: ipfwを使ってみよう

FreeBSDでファイアウォール(ipfw)

FreeBSDでipfwを学ぶ。keep-stateって何ができるか、どう使うか知っていますか?

/etc/rc.conf  で  ipfw を有効にする

/etc/rc.conf に、以下の行を追加する。em0 の部分は、適切な device名 に変更す ること(ifconfig -a で確認できる)。

firewall_enable="YES"
firewall_logdeny="YES"
firewall_script="/usr/local/etc/ipfw.rules"
firewall_interface="em0"
firewall_type="workstation"
sudo sysrc firewall_enable="YES" && sudo sysrc firewall_logdeny="YES" && sudo sysrc firewall_type="workstation"
echo "net.inet.ip.fw.verbose_limit=5" >> /etc/sysctl.conf
sudo sysrc firewall_script="/usr/local/etc/ipfw.rules"

Well Known Port

ipfw 設定ファイルの例

【参考サイト】FreeBSDでファイアウォール(ipfw)

/usr/local/etc/ipfw.rules

#! /bin/sh
#
 
IPF="ipfw -q add"
ipfw -q -f flush
 
#loopback
$IPF 10 allow all from any to any via lo0
$IPF 20 deny all from any to 127.0.0.0/8
$IPF 30 deny all from 127.0.0.0/8 to any
$IPF 40 deny tcp from any to any frag
 
# statefull
$IPF 50 check-state
$IPF 60 allow tcp from any to any established
$IPF 70 allow all from any to any out keep-state
$IPF 80 allow icmp from any to any
 
# open port ftp (20,21), ssh (22), mail (25)
# http (80), dns (53) , ntp(123) , https(443) mail-over(587) imaps(993 or 995) etc
$IPF 90 allow tcp from any to any 20 in
$IPF 100 allow tcp from any to any 20 out
$IPF 110 allow tcp from any to any 21 in
$IPF 120 allow tcp from any to any 21 out
$IPF 130 allow tcp from any to any 22 in
$IPF 140 allow tcp from any to any 22 out
$IPF 150 allow tcp from any to any 25 in
$IPF 160 allow tcp from any to any 25 out
$IPF 170 allow udp from any to any 53 in
$IPF 175 allow tcp from any to any 53 in
$IPF 180 allow udp from any to any 53 out
$IPF 185 allow tcp from any to any 53 out
$IPF 200 allow tcp from any to any 80 in
$IPF 210 allow tcp from any to any 80 out
$IPF 220 allow tcp from any to any 123 in
$IPF 230 allow tcp from any to any 123 out
$IPF 240 allow tcp from any to any 443 in
$IPF 250 allow tcp from any to any 443 out
$IPF 260 allow tcp from any to any 587 in
$IPF 270 allow tcp from any to any 587 out
$IPF 280 allow tcp from any to any 993 in
$IPF 290 allow tcp from any to any 993 out
$IPF 300 allow tcp from any to any 995 in
$IPF 310 allow tcp from any to any 995 out
 
# deny and log everything
$IPF 500 deny log all from any to any

設定内容の確認

ipfw の設定情報(ルールリスト)は、ipfw show で確認できる.

   # ipfw show

ipfw ルールの動作確認

まずは,実在するマシンに telnet してみる.多分 接続が拒否されると思いますが、それはそれで良いのです.つまり, telnet のパケットが外部に出ているということが分かります.

[image]

sysctl コマンドで、net.inet.ip.fw.verbose=1 を設定すると、 /var/log/secuty ファイルにログが記録されるようになる. (システムを再起動すると、net.inet.ip.fw.verbose の値は元に戻る)。

ipfw show sysctl net.inet.ip.fw.verbose=1 cd /var/log cat security

ログファイルのローテーションを設定する方法
/var/log/security は、ログローテーションに設定済み


Total access 317:本日 2:昨日 2

Counter: 317, today: 2, yesterday: 2

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS