Skip to content

Instantly share code, notes, and snippets.

@jiverson
Forked from ryanzhou/pf.md
Last active August 29, 2015 14:08
Show Gist options
  • Save jiverson/bc3e9658dc7fd961fc29 to your computer and use it in GitHub Desktop.
Save jiverson/bc3e9658dc7fd961fc29 to your computer and use it in GitHub Desktop.
Yosemite port forwarding

Getting gaviota-proxy to work in OS X Yosemite

Some parts taken from: https://gist.github.com/kujohn/7209628

ipfw is officially deprecated and removed in OS X Yosemite. If you don't want to run sudo for gaviota-proxy(which then you can also debug) you have to handle the port forwarding with the program pf.

1. Anchor file

Create file /etc/pf.anchors/mindflash, the port forward needs to match your dev.js config for gaviota-proxy.

rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port = 80 -> 127.0.0.1 port 3080
rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port = 443 -> 127.0.0.1 port 3443

Or if you want to connect via wireless

rdr pass inet proto tcp from any to 127.0.0.1 port = 80 -> 127.0.0.1 port 3080
rdr pass inet proto tcp from any to 127.0.0.1 port = 443 -> 127.0.0.1 port 3443

Note: Trailing line break is important.

2. Reference anchor in pf.conf

Insert rdr-anchor "mindflash" and load anchor "mindflash" from "/etc/pf.anchors/mindflash" at correct places in /etc/pf.conf, so that it looks like this:

scrub-anchor "com.apple/*"
nat-anchor "com.apple/*"
rdr-anchor "com.apple/*"
rdr-anchor "mindflash"  # mindflash port forwarding
dummynet-anchor "com.apple/*"
anchor "com.apple/*"
load anchor "com.apple" from "/etc/pf.anchors/com.apple"
load anchor "mindflash" from "/etc/pf.anchors/mindflash"  # mindflash port forwarding

3. Enabling pf

Note: pf is not at this time enabled(-e) by default on Yosemite on boot.

You can enable pf manually via sudo pfctl -ef /etc/pf.conf

You can disable pf manually via sudo pfctl -df /etc/pf.conf

However, to enable pf automatically after every boot, save the following as /System/Library/LaunchDaemons/com.apple.pfctl.plist:

<key>ProgramArguments</key>
<array>
<string>pfctl</string>
<string>-e</string>
<string>-f</string>
<string>/etc/pf.conf</string>
</array>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment