Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dch
Forked from f1sherman/forwarding-example.md
Created June 15, 2016 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dch/ea2cb9b446cda9390c2109c5e1e46817 to your computer and use it in GitHub Desktop.
Save dch/ea2cb9b446cda9390c2109c5e1e46817 to your computer and use it in GitHub Desktop.
Port Forwarding Example in OS X El Capitan

Add the following to /etc/pf.anchors/myname:

rdr pass on lo0 inet proto tcp from any to any port 80 -> 127.0.0.1 port 4000
rdr pass on lo0 inet proto tcp from any to any port 443 -> 127.0.0.1 port 4001

Add the following to /etc/pf-myname.conf:

rdr-anchor "forwarding"
load anchor "forwarding" from "/etc/pf.anchors/myname"

Add the following to /Library/LaunchDaemons/com.apple.pfctl-myname.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>com.apple.pfctl-myname</string>
     <key>Program</key>
     <string>/sbin/pfctl</string>
     <key>ProgramArguments</key>
     <array>
          <string>pfctl</string>
          <string>-e</string>
          <string>-f</string>
          <string>/etc/pf-myname.conf</string>
     </array>
     <key>RunAtLoad</key>
     <true/>
     <key>KeepAlive</key>
     <false/>
</dict>
</plist>

Run the following command to have it start at boot:

sudo launchctl load -w /Library/LaunchDaemons/com.apple.pfctl-myname.plist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment