【问题标题】:Using pfctl on Mac OS 10.11 (El Capitan) to forward ports在 Mac OS 10.11 (El Capitan) 上使用 pfctl 转发端口
【发布时间】:2015-10-09 15:03:05
【问题描述】:

我目前正在测试我的开发环境是否可以在即将推出的新 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。这是我的配置文件:

~/port-forwarding/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 的使用方式是否发生了变化,或者我做错了什么,或者是否有可以报告的错误。

非常感谢

尼克

【问题讨论】:

  • 有人在superuserthis comment 上询问过它,如果您愿意更改要转发到的端口,这可能会有所帮助。无论如何,您可能想要关注该帖子,因为它属于那里而不是在 stackoverflow 上。

标签: macos apache vagrant portforwarding osx-elcapitan


【解决方案1】:

这仅适用于 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 测试版中,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 -

【讨论】:

  • 我刚刚升级到 10.11 Beta 4,它似乎可以像以前一样工作。
  • 确保你使用 sudo:echo "rdr pass proto tcp from any to any port {80,8080} -> 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 的本地环回转发。
猜你喜欢
  • 2016-08-21
  • 2017-04-19
  • 1970-01-01
  • 2016-03-15
  • 2020-05-21
  • 1970-01-01
  • 2016-03-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多