[FreeBSD] FreeBSD - PF Firewall (1)

看板FreeBSD作者時間21年前 (2005/01/18 02:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
FreeBSD with Packet Filter(PF) Firewall - (1) - PF 於 July 2003 從 OpenBSD 中 porting 到 FreeBSD ports collection。 - PF 在 November 2004 成為 FreeBSD 系統的核心部份。 - PF 和 ALTQ 確定在 FreeBSD 5.3 RELEASE 中支援。 使用 PF 有兩種方式:一、模組載入;二、編入核心。 如果使用舊的 FreeBSD 版本,可以由 ports collection 中安裝。 # cd /usr/ports/security/pf ; make install (註:ports 中的 PF 是 OpenBSD 3.4 的版本,正式 porting 至 FreeBSD 核心部份的版本則是 OpenBSD 3.5) 注意:以下環境皆是由 FreeBSD 5.3 的環境下測試,請依照不同版本視情形調整。 ※ PF 啟動方式 [ 模組載入 ] #################### ### /etc/rc.conf ### #################### pf_enable="YES" # 啟動 PF pf_rules="/etc/pf.conf" # PF 的設定檔位置 pf_flags="" # PF 的參數 pflog_enable="YES" # 啟動 PFLOG pflog_logfile="/var/log/pflog" # PFLOG 紀錄檔的位置 pflog_flags="" # PFLOG 的參數 如果要使 PF 支援 gateway 則,多加入下一行: gateway_enable="YES" [ 編入核心 ] ############################## ### 將如下幾行加入至核心中 ### ############################## device bpf device pf device pflog device pfsync - device bpf 是 FreeBSD log traffic,如果有使用 pflog,請務必編入。 - device pf 是啟動 PF firewall - device pflog 是啟動虛擬網路設備來記錄流量(經由 bpf) - device pfsync 是虛擬網路設備來監視網路狀態。 ####################### ### vi /etc/rc.conf ### ####################### pf_enable="YES" # 啟動 PF pf_rules="/etc/pf.conf" # PF 的設定檔位置 pf_flags="" # PF 的參數 pflog_enable="YES" # 啟動 PFLOG pflog_logfile="/var/log/pflog" # PFLOG 紀錄檔的位置 pflog_flags="" # PFLOG 的參數 如果要使 PF 支援 gateway 則,多加入下一行: gateway_enable="YES" 最後重新編譯 kernel。 ※ PF 設定檔 標準的格式如下: ################################################################# # macro definitions ################################################################# # options: "set" ################################################################# # scrub rules: "scrub" ################################################################# # NAT rules: "rdr", "nat", "binat" ################################################################# # filtering rules: "antispoof", "block", "pass" ################################################################# 不需 NAT 的簡單設定檔如下: ################################################################# # macro definitions ################################################################# extdev='fxp0' # 對外的網路卡 ################################################################# # options: "set" ################################################################# set limit frags 30000 # 保存 30000 個 frags set limit states 25000 # 保存 25000 個狀態表的數量 # answer blocked TCP packets with TCP RSP and # blocked UDP with ICMP destination-unreachable set block-policy return set require-order yes set optimization aggressive set loginterface $extdev ################################################################# # scrub rules: "scrub" ################################################################# scrub in all ################################################################# # filtering rules: "antispoof", "block", "pass" ################################################################# antispoof log quick for $extdev # block ipv6 packets #block inet6 all pass in all pass out all 需 NAT 的簡單設定檔如下: ################################################################# # macro definitions ################################################################# extdev='fxp0' # 對外的網路卡 intranet='192.168.0.0/24' # 內部虛擬IP ################################################################# # options: "set" ################################################################# set limit frags 30000 # 保存 30000 個 frags set limit states 25000 # 保存 25000 個狀態表的數量 # answer blocked TCP packets with TCP RSP and # blocked UDP with ICMP destination-unreachable set block-policy return set require-order yes set optimization aggressive set loginterface $extdev ################################################################# # scrub rules: "scrub" ################################################################# scrub in all ################################################################# # NAT rules: "rdr", "nat", "binat" ################################################################# nat on $extdev inet from $intranet to any -> $extdev ## 這裡特別注意的是,如果你的 extdev 綁了多個 IP ## 那麼 NAT 出去的 IP 會採取 round-robin 出去 (酷) ################################################################# # filtering rules: "antispoof", "block", "pass" ################################################################# antispoof log quick for $extdev # block ipv6 packets #block inet6 all pass in all pass out all ※ 重新啟動系統 -- \||||||/ 「一直到中古時期結束之前,理性代表具備一種心智,能夠看 q ^ ^ p 出各種事物之間精神層次的關聯、在主體與客體之間的律動 ╰ 0 ╯ o 、微妙平衡或分配比率。 」 </ 菠 \-/ - Seven Life Lessons of Chaos -- ※ Origin: SayYA 資訊站 <bbs.sayya.org> ◆ From: 61-224-80-30.dynamic.hinet.net
文章代碼(AID): #11w_rn00 (FreeBSD)
文章代碼(AID): #11w_rn00 (FreeBSD)