linux防火墙pf,Mac下使用PF进行端口转发和防火墙配置(类似Linux的iptables)

首先我们要开启系统的端口转发功能。

本次开机生效:

# IPv4 的转发

$sudo sysctl -w net.inet.ip.forwarding=1net.inet.ip.forwarding:0 -> 1# IPv6 的转发

$sudo sysctl -w net.inet6.ip6.forwarding=1net.inet6.ip6.forwarding:0 -> 1

开机启动配置,需以 root 身份添加或修改 /etc/sysctl.conf 文件,加入以下两行:

net.inet.ip.forwarding=1net.inet6.ip6.forwarding=1

查看当前端口转发功能状态:

$ sudo sysctl -a | grepforward

net.inet.ip.forwarding:0net.inet6.ip6.forwarding:0

开启端口转发之后,即可配置端口转发规则。你可以跟着手册来:

$ manpfctl

$man pf.conf

或者跟着下文手动新建文件。如/etc/pf.anchors/http文件内容如下:

rdr pass on lo0 inet proto tcp from any to any port 80 -> 127.0.0.1 port 8080rdr pass on lo0 inet proto tcp from any to any port443 -> 127.0.0.1 port 4443rdr pass on en0 inet proto tcp from any to any port80 -> 127.0.0.1 port 8080rdr pass on en0 inet proto tcp from a

你可能感兴趣的:(linux防火墙pf)