Macos 在Mac OS 10.11(El Capitan)上使用pfctl转发端口

Macos 在Mac OS 10.11(El Capitan)上使用pfctl转发端口,macos,apache,vagrant,portforwarding,osx-elcapitan,Macos,Apache,Vagrant,Portforwarding,Osx Elcapitan,我目前正在测试我的开发环境是否将在即将推出的MacOS10.11上运行,以及是否可以在发布后立即升级。在我的测试机器上,我目前正在运行Beta Preview 3。一切似乎都很顺利 我只需要获得pfctl来转发我的端口。我使用Vagrant和Parallels Desktop为本地web服务器运行Debian系统。Vagrant将主机上的端口8080转发到来宾上的端口80。因此,127.0.0.1:8080工作正常。但在一些项目中,我希望本地域与生产中的域完全相同。(没有:8080)我更喜欢它

我目前正在测试我的开发环境是否将在即将推出的MacOS10.11上运行,以及是否可以在发布后立即升级。在我的测试机器上,我目前正在运行Beta Preview 3。一切似乎都很顺利

我只需要获得
pfctl
来转发我的端口。我使用Vagrant和Parallels Desktop为本地web服务器运行Debian系统。Vagrant将主机上的端口8080转发到来宾上的端口80。因此,
127.0.0.1:8080
工作正常。但在一些项目中,我希望本地域与生产中的域完全相同。(没有:8080)我更喜欢它

为此,我使用
pfctl
在主机上转发80到8080。以下是我的配置文件:

~/port-forwarding/pf.conf

~/port-forwarding/rules.conf

要启用它,我运行:

sudo pfctl -vnf ~/port-forwarding/pf.conf
sudo pfctl -evf ~/port-forwarding/pf.conf
这给了我这样的信息:

pfctl: Use of -f option, could result in flushing of rules
present in the main ruleset added by the system at startup.
See /etc/pf.conf for further details.

rdr-anchor "forwarding" all

Loading anchor forwarding from /Users/nick/port-forwarding/rules.conf
rdr pass on lo0 inet proto tcp from any to any port = 80 -> 127.0.0.1 port 8080
rdr pass on lo0 inet proto tcp from any to any port = 443 -> 127.0.0.1 port 4433
pfctl: Use of -f option, could result in flushing of rules
present in the main ruleset added by the system at startup.
See /etc/pf.conf for further details.

No ALTQ support in kernel
ALTQ related functions disabled
rdr-anchor "forwarding" all

Loading anchor forwarding from /Users/nick/port-forwarding/rules.conf
rdr pass on lo0 inet proto tcp from any to any port = 80 -> 127.0.0.1 port 8080
rdr pass on lo0 inet proto tcp from any to any port = 443 -> 127.0.0.1 port 4433
pf enabled
logout
Saving session...completed.
sudo pfctl-s nat说:

到目前为止,我认为它看起来不错。但它就是不起作用

127.0.0.1:80
-无连接
127.0.0.1:8080
-有效

我在约塞米蒂使用相同的文件,在那里效果很好

是否有人知道如何使用
pfctl
发生了变化,或者我做错了什么,或者是否有可以报告的错误

非常感谢


尼克这只适用于OSX 10.11-El Capitan-Public Beta 1

x-post发件人:

在最新的10.11测试版中,127.0.0.1被阻止。解决方案是什么?使用127.0.0.2。为此:

首先将127.0.0.2添加到环回别名
sudo ifconfig lo0别名127.0.0.2以上

修改pf规则以使用新别名。
rdr将协议tcp从任意端口传递到任意端口80->127.0.0.2端口8080

从命令行,不使用文件:


echo“rdr将协议tcp从任意端口传递到任意端口{808080}->127.0.0.2端口8080”| pfctl-Ef-
有人在上询问过这一问题,如果您愿意更改转发到的端口,尤其可能会有所帮助。不管怎样,你可能想关注这篇文章,因为它比stackoverflow更属于那里。我刚刚升级到10.11 Beta 4,它似乎和以前一样工作。确保你使用sudo:
echo“rdr pass proto-tcp from any to any port{808080}->127.0.0.2 port 8080”| sudo pfctl-Ef-
,作为其他人的注意事项,127.0.0.1在El Capitan的公开发行版本中似乎没有被阻止,例如在OS X 10.11.5上。我已经能够成功地在El Capitan上针对127.0.0.1设置基于pf的本地环回转发。
sudo pfctl -vnf ~/port-forwarding/pf.conf
sudo pfctl -evf ~/port-forwarding/pf.conf
pfctl: Use of -f option, could result in flushing of rules
present in the main ruleset added by the system at startup.
See /etc/pf.conf for further details.

rdr-anchor "forwarding" all

Loading anchor forwarding from /Users/nick/port-forwarding/rules.conf
rdr pass on lo0 inet proto tcp from any to any port = 80 -> 127.0.0.1 port 8080
rdr pass on lo0 inet proto tcp from any to any port = 443 -> 127.0.0.1 port 4433
pfctl: Use of -f option, could result in flushing of rules
present in the main ruleset added by the system at startup.
See /etc/pf.conf for further details.

No ALTQ support in kernel
ALTQ related functions disabled
rdr-anchor "forwarding" all

Loading anchor forwarding from /Users/nick/port-forwarding/rules.conf
rdr pass on lo0 inet proto tcp from any to any port = 80 -> 127.0.0.1 port 8080
rdr pass on lo0 inet proto tcp from any to any port = 443 -> 127.0.0.1 port 4433
pf enabled
logout
Saving session...completed.
No ALTQ support in kernel
ALTQ related functions disabled
rdr-anchor "forwarding" all