深入解析PF数据包过滤:规则、状态与优化策略
1. 端口范围操作
在数据包过滤中,我们常常需要对端口范围进行精确控制。可以使用包含范围运算符(:)来指定端口范围。比如,要包含端口1000和2000,可以这样写规则:
pass in on egress proto tcp from any to 192.0.2.12 port 1000:2000
注意,冒号两边不能有空格。若要允许所有小于1000和大于2000的端口的流量,可使用反向范围运算符(<>):
pass in on egress proto tcp from any to 192.0.2.12 port 1000 <> 2000
通过范围操作,我们能用很少的规则表达大量的端口。
2. 完整规则集示例
以下是一个桌面机器的完整规则集,它运用了前面提到的许多特性。接口组 egress 连接到公共网络, inside 连接到私有网络。
u set skip on lo
v block
w pass in on egress from egress:network
x pass in on inside from inside:network
y pass in on egress proto tcp fro
超级会员免费看
订阅专栏 解锁全文
1454

被折叠的 条评论
为什么被折叠?



