This guide enables port forwarding for foo.com
to localhost:3000
. Tested on macOS High Sierra.
$ sudo nvim /etc/hosts
Add the following:
127.0.0.1 foo.com
$ sudo nvim /etc/pf.anchors/foo.conf
Add the following, (notice the port number at the end):
rdr pass on lo0 inet proto tcp from any to any port 80 -> 127.0.0.1 port 3000
$ sudo vim /etc/pf.conf
Add the following,
rdr-anchor "forwarding"
load anchor "forwarding" from "/etc/pf.anchors/foo.conf"
$ sudo pfctl -ef /etc/pf.anchors/foo.conf
If it doesnt work make sure the following is set:
$ sudo sysctl -a | grep forwarding
net.inet.ip.forwarding: 1
net.inet6.ip6.forwarding: 1
Not set up? Set it like this:
sudo sysctl -w net.inet.ip.forwarding=1
sudo sysctl -w net.inet6.ip6.forwarding=1
Optionally, add it to
/etc/sysctl.conf
, for the settings to persist.
To quickly, turn on and off: