[FreeBSD]PCルーターを作ろう。pf編。
次は pf の設定。
kernel に
device pf
device pflog
device pfsync
options ALTQ
options ALTQ_CBQ # Class Bases Queuing (CBQ)
options ALTQ_RED # Random Early Detection (RED)
options ALTQ_RIO # RED In/Out
options ALTQ_HFSC # Hierarchical Packet Scheduler (HFSC)
options ALTQ_PRIQ # Priority Queuing (PRIQ)
#options ALTQ_NOPCC # Required for SMP build
↑うちはPIII-500の1cpuなんで、コメント。
を追加。
rc.confに
pf_enable="YES" # Enable PF (load module if required)
pf_rules="/etc/pf.conf" # rules definition file for pf
pf_flags="" # additional flags for pfctl startup
pflog_enable="YES" # start pflogd(8)
pflog_logfile="/var/log/pflog" # where pflogd should store the logfile
pflog_flags="" # additional flags for pflogd startup
を追加。
設定ファイルは /etc/pf.conf
#macro
ext_if="ng0"
int_if="em0"
# Options: tune the behavior of pf, default values are given.
set timeout { interval 10, frag 30 }
set timeout { tcp.first 120, tcp.opening 30, tcp.established 86400 }
set timeout { tcp.closing 900, tcp.finwait 45, tcp.closed 90 }
set timeout { udp.first 60, udp.single 30, udp.multiple 60 }
set timeout { icmp.first 20, icmp.error 10 }
set timeout { other.first 60, other.single 30, other.multiple 60 }
set timeout { adaptive.start 0, adaptive.end 0 }
set limit { states 10000, frags 5000 }
set loginterface ng0
set optimization normal
set block-policy drop
#set require-order yes
#set fingerprints "/etc/pf.os"
#### Traffic Normalization ####
scrub in on $ext_if all fragment reassemble # 入りのパケットのフラグメントを再構成
scrub out on $ext_if all max-mss 1414 # 出るパケットのmssを1414に書き換え
#参考サイトからコピペ。
#nat
nat on $ext_if from ($int_if)/24 to any -> ($ext_if)
#filter
pass in all #ちょ、おまwwwww
pass out all #とりあえず、動かない原因が nat にあるのか filter にあるのか切り分けたかったので(汗
#loopback
pass in quick on lo0 all
pass out quick on lo0 all
#local
pass in quick on $int_if all
pass out quick on $int_if all
とりあえず、フィルターの設定は後回しで、nat をまず動かす。
kernelを再構築。そして、reboot。
rc.conf で pf を実行するようにしているの、起動時に立ち上がるんだけど、
デバイス "ng0" は mpd 実行後に作られる仮想デバイスなので、自動時に nat は動作しません。
なので、起動後
su
mpd -b
sh /etc/rc.d/pf restart
という流れになります。
次はdhcpdだ。