硬體為 HP NETSERVER 800(Pentium III 1000、256M 記憶體、兩張 Intel 82559 網卡),採用最小化安裝,並裝上 src 與 ports。由於 cvs 源碼無法取得,最後改以源碼編譯方式處理。
複製 GENERIC 為 cache 並加入 pf 相關選項:
device pf device pflog device pfsync options ALTQ options ALTQ_CBQ
接著編譯並安裝內核,重啟後即可。
在 /etc/rc.conf 讓 pf 自動載入,並設定兩張網卡、開啟 IP 轉發:
defaultrouter="218.4.xxx.xxx" ifconfig_fxp0="inet 218.4.xxx.xxx netmask 255.255.255.248" ifconfig_fxp1="inet 192.168.2.10 netmask 255.255.255.0" gateway_enable="YES" pf_enable="YES" pflog_enable="YES" pflog_logfile="/var/log/pflog"
並在 /etc/sysctl.conf 開啟 net.inet.ip.forwarding=1。
以下設定可實現共享上網,並把 80、21 等服務做位址轉發(NAT / RDR):
wan_if="fxp0" lan_if="fxp1" inter_net="192.168.2.0/24" web_server="192.168.2.3" ftp_server="192.168.2.3" scrub in all nat on $wan_if from $inter_net to any -> fxp0 rdr on $wan_if proto tcp from any to any port 21 -> $ftp_server port 21 rdr on $wan_if proto tcp from any to any port 49152:65535 -> $ftp_server port 49152:65535 pass in quick on $wan_if proto tcp from any to $ftp_server port 21 keep state pass in quick on $wan_if proto tcp from any to $ftp_server port > 49151 keep state pass out quick on $lan_if proto tcp from any to $ftp_server port 21 keep state pass out quick on $lan_if proto tcp from any to $ftp_server port > 49151 keep state pass in all pass out all
被註解掉的 Danger_Port 段落,可用來封鎖 445、135、139 等高危險連接埠,需要時取消註解即可。整體目標是驗證 pf 與 Squid 結合做反向代理的可行性;生產環境仍應針對伺服器內核做進一步優化。