2015-07-20 90 views
8

我目前正在测试我的开发环境是否会在即将推出的新Mac OS 10.11上运行,如果我可以在其发布后立即升级。在我的测试机器上,我正在运行Beta Preview 3.一切似乎都运行良好。在Mac OS 10.11(El Capitan)上使用pfctl转发端口

我只能得到pfctl转发我的端口。我使用Vagrant和Parallels Desktop为本地Web服务器运行Debian系统。 Vagrant将主机上的端口8080转发到guest虚拟机上的8080端口。所以127.0.0.1:8080工作正常。但是在一些项目中,我希望具有与生产中相同的本地域。 (没有:8080)另外我更喜欢它。 ;-)

要做到这一点,我使用pfctl在主机上转发80到8080。下面是我的配置文件:

〜/端口转发/ pf.conf中

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

〜/端口转发/ 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. 

须藤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 - 工程

我用约塞米蒂相同的文件,它工作正常那里。

有没有人知道是否有改变如何使用pfctl或如果我做错了什么,或者如果有一个可以报告的错误。

非常感谢

尼克

+1

有人问关于它的[超级] (http://superuser.com/questions/938999/osx-10-11-el-capitan-beta-pf-conf-behaviour-changed)和[此评论](http://superuser.com/questions/938999/osx-10-11-el-capitan-beta-pf-conf-behavior-changed#comment1281706_938999)尤其可以帮助您更改要转发的端口。 无论如何,你可能想要关注这个帖子,因为它不止在stackoverflow上。 –

回答

10

这仅适用于OSX 10.11 - 埃尔卡皮坦 - 公开测试版1

X-后从: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)

+0

我只是升级到10.11 Beta 4,它似乎像以前一样工作。 – Dafen

+0

太棒了! – Cory

+1

请确保您使用sudo: 'echo“rdr pass proto tcp from any to any {80,8080} - > 127.0.0.2 port 8080”| sudo pfctl -Ef -' – Irimia

相关问题