我想建立一个简单的转发规则(不是端口转发!)在FreeBSD 12.3上,它基于接收到的接口和外接接口进行过滤.IP网络不应该成为规则的一部分,因为它的作用就像各种IP的路由器。路由网络将由路由守护进程(带有OSPF的鸟)动态设置。
在使用PF的FreeBSD中,我只能按照每个过滤器规则([ "on" ifspec ]
)设置一个man 5 pf.conf:
pf-rule = action [ ( "in" | "out" ) ]
[ "log" [ "(" logopts ")"] ] [ "quick" ]
[ "on" ifspec ] [ route ] [ af ] [ protospec ]
hosts [ filteropt-list ]
我希望输入接口和输出接口的结合能够匹配.我怎么能这么做?
在使用nft
/nftables的Linux中,我会这样做:
define iface_site2site = { "tun0", "tun1", "tun9" }
[...]
chain forward {
type filter hook forward priority 0;
policy drop;
iifname $iface_site2site oifname $iface_site2site accept \
comment "Freely forward packets between site-to-site links, firewalled at final destination."
}
[...]
在使用iptables
的Linux中,我会这样做:
iptables -A [...] --in-interface tun+ --out-interface tun+ -j ACCEPT
如何在FreeBSD上进行上述操作?
我只是想澄清一下;我不是在寻找端口转发或NAT规则。
发布于 2022-11-01 11:03:43
在FreeBSD上,似乎不可能在一条规则中做到这一点。因此,我们可以使用match
规则在这些接口上标记入站流量,然后是两个pass
规则,一个用于in
,另一个用于out
,后者只允许流量在标记为这样的情况下退出。
如man pf.conf(5)在FreeBSD 12.3上所示:
与此规则匹配的标记数据包将使用指定的字符串进行标记。该标记充当内部标记,稍后可用于标识这些数据包。例如,这可用于提供接口之间的信任,并确定数据包是否已由转换规则处理。标签是“粘稠的”,这意味着即使该规则不是最后的匹配规则,也会对数据包进行标记。
它很好地提到了问题的用例(“提供接口之间的信任”)。
FreeBSD的tag
__s类似于Linux的netfilter中的mark
__s。
示例:
site_to_site_links = "{" tun0 tun1 tun9 "}"
[...]
block log all
# Allow forwarding freely between the site-to-site interfaces
# (not to self); traffic firewalled at final destination.
match in on $site_to_site_links from any to any tag S2S no state
pass in quick on $site_to_site_links to ! self no state
pass out quick on $site_to_site_links tagged S2S no state
请注意,流量也需要pass
ed in
,除非它是自己指定的,否则我们可能会绕过其他传入的防火墙规则。
其他调试技巧:启用pflog
(在rc.conf
中设置pflog_enable="YES"
)并使用tcpdump -e -n -i pflog0
查看被阻塞的内容。-e
选项显示哪条规则匹配将导致数据包被阻塞。
https://unix.stackexchange.com/questions/722232
复制相似问题