曾经的 ipfw 已经被 pf 所替换。你可以跟着手册来。$ man pfctl$ man pf.conf或者手动新建文件 /etc/pf.anchors/http。文件内容如下:rdr pass o
曾经的 ipfw 已经被 pf 所替换。
你可以跟着手册来。
$ man pfctl$ 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 port 443 -> 127.0.0.1 port 4443rdr pass on en0 inet proto tcp from any to any port 80 -> 127.0.0.1 port 8080rdr pass on en0 inet proto tcp from any to any port 443 -> 127.0.0.1 port 4443
检查其正确性。
$ sudo pfctl -vnf /etc/pf.anchors/http
修改 pf 的主配置文件 /etc/pf.conf
。
pf.conf 对指令的顺序有严格要求,相同的指令需要放在一起,否则会报错 Rules must be in order: options, normalization, queueing, translation, filtering.
# 在 rdr-anchor "com.apple/*" 下添加rdr-anchor "http-forwarding"# 在 load anchor "com.apple" from "/etc/pf.anchors/com.apple" 下添加load anchor "http-forwarding" from "/etc/pf.anchors/http"
最后导入并允许运行。
$ sudo pfctl -ef /etc/pf.conf
我又执行了如下命令强制重启 pf。
$ sudo pfctl -E
大功告成。
新版 Mac OS 10.11 EI Captian 加入了系统完整性保护机制,需重启到安全模式执行下述命令关闭文件系统保护:
$ csrutil enable --without fs
然后才能修改 /System/Library/LaunchDaemons/com.apple.pfctl.plist
文件实现开机自启用配置:
<string>pfctl</string><string>-e</string><string>-f</string><string>/etc/pf.conf</string>
添加了上述 -e
行。
使用下述命令关闭 pf:
$ sudo pfctl -d