我试图转发一个外部IP地址到另一个外部IP地址与PF。 等效的iptables命令是iptables -t nat -A OUTPUT -d [ipaddress1] -j DNAT --to-destination [ipaddress2]
。
我在我的pf.conf中尝试了各种forms的nat和rdr,例如:( $int_if
是内部接口, $ext_if
外部接口, $out_ad
是ipaddress1(地址redirect), $res_ad
是ipaddress2(地址redirect到)
nat on $int_if from 127.0.0.1 to $out_ad -> $res_ad rdr pass on $ext_if proto tcp from $out_ad to $res_ad -> 127.0.0.1 rdr pass on $int_if proto tcp from 127.0.0.1 to $out_ad -> $res_ad rdr pass log proto tcp from any to $out_ad -> $res_ad nat from $out_ad to $res_ad -> 127.0.0.1 nat on $ext_if from $out_ad to $res_ad -> $ext_if rdr on $int_if proto tcp from any to $out_ad -> $res_ad rdr pass quick on $ext_if proto tcp from any to $out_ad -> $res_ad
这些似乎都没有伎俩。 我也设置了sysctl net.inet.ip.forwarding=1
。 任何帮助将不胜感激。 谢谢
sysctl net.inet.ip.forwarding=1
这将只启用您的机器上的路由。 它可以工作,如果你想创build一个允许任何目标IP在外部接口(至less在理论上)(10.20.30.40是在这个例子中的最终目的地)
pass in inet proto tcp from any to 10.20.30.40
(只是一个想法)
但是你的rdr规则将不起作用,因为它们恰好在不同的界面(根据一些论坛post)是不允许的,或者只是简单地不工作
另一方面,公共NAT规则应该起作用,但是你将失去最终目的地的始发IP地址。 (故意的吗?)
nat on $ext_if inet from any to 10.20.30.40 -> ($ext_if:0) port 1024:65535 pass on $ext_if inet from any to 10.20.30.40 keep state
(或synproxy状态)
为了debugging目的,请尝试启用规则logging(通过将日志添加到传递规则,enabeling pflog和以下命令)
/etc/rc.conf ... pflog_enable="YES" pflog_logfile="/var/log/pflog ... # tcpdump -i pflog0 -n -e -ttt
哦,也许请提供一些简单的networking结构;)