Guide to add localhost:80 to localhost:8080 forwarding.
Since Mavericks stopped using the deprecated ipfw
(as of Mountain Lion), we'll be using pf
to allow port forwarding.
####1. anchor file
Create an anchor file under /etc/pf.anchors/<anchor file>
with your redirection rule like:
rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port 80 -> 127.0.0.1 port 8080
####2. Test the anchor file Parse and test your anchor file to make sure there are no errors:
sudo pfctl -vnf <anchor file>
####3. Reference the anchor in pf.conf
/etc/pf.conf
is the main configuration file that pf
loads at boot.
We'll need to load the anchor file we previously created:
rdr-anchor "forwarding"
load anchor "forwarding" from "/etc/pf.anchors/<anchor file>"
Make sure to add these entries to the appropriate spot, like:
scrub-anchor "com.apple/*"
nat-anchor "com.apple/*"
rdr-anchor "com.apple/*"
rdr-anchor "forwarding"
dummynet-anchor "com.apple/*"
anchor "com.apple/*"
load anchor "com.apple" from "/etc/pf.anchors/com.apple"
load anchor "forwarding" from "/etc/pf.anchors/com.custom"
####4. Load and enabling pf
pf
is not enabled by default in Mavericks, few ways to enable this:
-
Manually load and enable from a pf.conf file via
sudo pfctl -ef <pf.conf file>
-
Auto enable by creating a launch daemon via this doc to run
pfctl -ef <pf.conf file>
on boot. -
Auto enable by adding an
-e
(enable) to thepfctl
ProgramArgument in/System/Library/LaunchDaemons/com.apple.pfctl.plist
like this:
<key>ProgramArguments</key>
<array>
<string>pfctl</string>
<string>-e</string>
<string>-f</string>
<string>/etc/pf.conf</string>
</array>
There is the possibility that pf.conf
will be overriden with updates to the OS. It might be best to create your own pf config file and load them in additon to the main pf.conf
to prevent this.