9

我目前正在测试我的开发环境是否可以在即将推出的新 Mac OS 10.11 上运行,以及我是否可以在它发布后立即升级。在我的测试机器上,我目前正在运行 Beta Preview 3。一切似乎都运行良好。

我只能pfctl转发我的端口。我使用 Vagrant 和 Parallels Desktop 为我的本地 Web 服务器运行 Debian 系统。Vagrant 将主机上的 8080 端口转发到客户机上的 80。所以127.0.0.1:8080工作正常。但在某些项目中,我希望拥有与生产环境完全相同的本地域。(没有:8080)我也更喜欢它。;-)

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

~/端口转发/pf.conf

rdr-anchor "forwarding"
load anchor "forwarding" from "/Users/nick/port-forwarding/rules.conf"

~/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 

要启用它,我运行:

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说:

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

到目前为止,它看起来不错,我认为。但它只是行不通。

127.0.0.1:80- 没有连接 127.0.0.1:8080- 工作

我在 Yosemite 上使用相同的文件,它在那里工作得很好。

有谁知道使用方法是否发生了变化,pfctl或者我做错了什么,或者是否有可以报告的错误。

非常感谢

缺口

4

1 回答 1

12

这仅适用于 OSX 10.11 - El Capitan - Public Beta 1

x-post 来自: https ://superuser.com/questions/938999/osx-10-11-el-capitan-beta-pf-conf-behaviour-changed/943981#943981

在最新的 10.11 beta 中,127.0.0.1 被阻止。解决方案?使用 127.0.0.2。去做这个:

首先将 127.0.0.2 添加到环回别名 sudo ifconfig lo0 alias 127.0.0.2 up

修改您的 pf 规则以使用新别名。 rdr pass proto tcp from any to any port 80 -> 127.0.0.2 port 8080

从命令行,不使用文件:

echo "rdr pass proto tcp from any to any port {80,8080} -> 127.0.0.2 port 8080" | pfctl -Ef - <-- 请务必添加最后一个勾号,您正在使用 STDIN 管道)

于 2015-07-22T18:00:31.490 回答