看板FreeBSD
标 题Re: [FreeBSD] FreeBSD - PF Firewall
发信站Shaw Residential Internet (Tue Jan 18 08:48:20 2005)
转信站ptt!ctu-reader!ctu-peer!news.nctu!newshub.sdsu.edu!elnk-nf2-pas!elnk-p
真好,感谢 "或许…我不是我" <
[email protected]> 前辈
> FreeBSD with Packet Filter(PF) Firewall - (1)
> FreeBSD with Packet Filter(PF) Firewall - (2)
> FreeBSD with Packet Filter(PF) Firewall - (3)
跟之前摸索中找到的
http://freebsd.ntut.idv.tw/document/freebsd_pf_nat.html
也有点像 .
恕後学鲁顿, 可否请教 /etc/pf.conf 设定
我的环境:
fBSD 在 192.168.1.2 ; 跑各种 server
及 intranet 192.168.1.0/24 ; intranet 还有多部 windowsXP .
router, 在 192.168.1.1, 已设 将外来 access 全指过来给 fBSD 这台 server.
希望能限制 外出频宽 ; 但不限制 内部频宽 .
限制 外出频宽 如果能限制 每个 ip 最多达某个上限频宽 就最好.
这是我的 /etc/pf.conf ; 能不能请帮我看一眼 这样设可以吗?
#######################
# /etc/pf.conf 开始
# neuro : 1 macro definitions
extdev='fxp0' # 对外的网路卡
# neuro : 2 otions: "set"
set limit frags 30000 # 保存 30000 个 frags
set limit states 25000 # 保存 25000 个状态表的数量
set block-policy return
set require-order yes
set optimization aggressive
set loginterface $extdev
scrub in all
# neuro - ALTQ 定义频宽控制的进出
# Outgoing bandwidth limit
altq on $extdev cbq bandwidth 512Kb queue { std_out }
queue std_out bandwidth 256Kb cbq (default)
altq on $extdev cbq bandwidth 100Mb queue { std_in }
queue std_in bandwidth 2Mb cbq (default borrow)
# neuro - 4 filtering rules: "antispoof", "block", "pass"
antispoof log quick for $extdev
pass in all
pass out all
block in proto tcp from 163.19.218.225 to any port 80
block in proto tcp from 163.22.3.8 to any port 80
block in proto tcp from 24.187.253.176 to any port 80
block in proto tcp from 61.135.0.0/16 to any port 80
# ... 一堆 被我 block 的 spider, 或不良 ip
block from 128.255.208.111 to any
block from 134.174.165.58 to any
block from 157.82.247.112 to any
block from 163.150.15.246 to any
block from 163.17.209.44 to any
# ... 一堆 被我 block 的 害客 不良 ip - 那些乱来 ssh telnet 的
# end of /etc/pf.conf 结束
#######################
个人小事,
感谢 前辈拨冗费心了 :)
谢谢
<: Neuro :>
http://neuro.ohbi.net
http://neuro.no-ip.info
http://neuro.dyndns.tv
http://neuro.supt.net
http://neuro.taiwantop.com
e-mails :
[email protected]
[email protected]
===
"或许…我不是我" <
[email protected]> 撰写於邮件新闻:
[email protected]...
>
> 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