再次工作!
MacOS Yosemite 完全删除了 ipfw (IP-Firewall),现在只使用 pf (Packet Filter)。所以所有我们习惯的默认转发都没有了!
为了让它再次工作,我使用了这个很棒的教程:来自 Sal Ferrarello 的 Mac pfctl Port Forwarding 并对其进行了更改以支持常用的 Rails 服务器。把它放在终端和..
它再次工作!
成功的过程(终端命令)
激活 Rails 端口转发 (如果需要,添加更多)
echo "
rdr pass inet proto tcp from any to any port 3000 -> 127.0.0.1 port 3000
rdr pass inet proto tcp from any to any port 3001 -> 127.0.0.1 port 3001
rdr pass inet proto tcp from any to any port 3002 -> 127.0.0.1 port 3002
rdr pass inet proto tcp from any to any port 3003 -> 127.0.0.1 port 3003
rdr pass inet proto tcp from any to any port 3004 -> 127.0.0.1 port 3004
rdr pass inet proto tcp from any to any port 3005 -> 127.0.0.1 port 3005
rdr pass inet proto tcp from any to any port 3006 -> 127.0.0.1 port 3006
rdr pass inet proto tcp from any to any port 3007 -> 127.0.0.1 port 3007
rdr pass inet proto tcp from any to any port 3008 -> 127.0.0.1 port 3008
rdr pass inet proto tcp from any to any port 3009 -> 127.0.0.1 port 3009
rdr pass inet proto tcp from any to any port 3010 -> 127.0.0.1 port 3010
rdr pass inet proto tcp from any to any port 4242 -> 127.0.0.1 port 4242
rdr pass inet proto tcp from any to any port 9292 -> 127.0.0.1 port 9292
" | sudo pfctl -ef -
显示当前转发规则 (检查哪些规则有效)
sudo pfctl -s nat
停止端口转发 (小心!再次停止!)
sudo pfctl -F all -f /etc/pf.conf
.. 我仍然想念 SnowLeopard,如今开发人员的生活是如此轻松 ..
更新:
这仅在下次重新启动之前有效。我尝试了很多让它自动工作,我更改了 /etc/pf.conf,我更改了 pf 守护进程.. 但没有任何效果!
所以我制作了自己的守护程序,它只在启动时加载我的开发端口,效果很好!
/Library/LaunchDaemons/dev.development.servers.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>dev.development.servers</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>-c</string>
<string>
echo "
rdr pass inet proto tcp from any to any port 3000 -> 127.0.0.1 port 3000
rdr pass inet proto tcp from any to any port 3001 -> 127.0.0.1 port 3001
rdr pass inet proto tcp from any to any port 3002 -> 127.0.0.1 port 3002
rdr pass inet proto tcp from any to any port 3003 -> 127.0.0.1 port 3003
rdr pass inet proto tcp from any to any port 3004 -> 127.0.0.1 port 3004
rdr pass inet proto tcp from any to any port 3005 -> 127.0.0.1 port 3005
rdr pass inet proto tcp from any to any port 3006 -> 127.0.0.1 port 3006
rdr pass inet proto tcp from any to any port 3007 -> 127.0.0.1 port 3007
rdr pass inet proto tcp from any to any port 3008 -> 127.0.0.1 port 3008
rdr pass inet proto tcp from any to any port 3009 -> 127.0.0.1 port 3009
rdr pass inet proto tcp from any to any port 3010 -> 127.0.0.1 port 3010
rdr pass inet proto tcp from any to any port 4242 -> 127.0.0.1 port 4242
rdr pass inet proto tcp from any to any port 9292 -> 127.0.0.1 port 9292
" | sudo pfctl -ef -
</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>UserName</key>
<string>root</string>
</dict>
</plist>