Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Redirect port 3080/3443 to 80/443 for local dev
#Requests from outside
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 3080
iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-ports 3443
#Requests from localhost
iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 80 -j REDIRECT --to-ports 3080
iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 443 -j REDIRECT --to-ports 3443
@m5m1th

This comment has been minimized.

Copy link
Owner Author

commented May 5, 2014

Set the app to listen on port 3000/3443 or whatever you want, anything over 1024 is fine to use as a normal user. Then sudo run those iptables commands and it should forward any traffic from ports 80/443 to 3000/3443. If you want them to persist across reboots, stick them in a startup script somewhere like /etc/rc.local

@m5m1th

This comment has been minimized.

Copy link
Owner Author

commented May 5, 2014

The above only works on linux. For a mac, it might be something like:

sudo ipfw add 100 fwd 127.0.0.1,3000 tcp from any to any 80 in
sudo ipfw add 200 fwd 127.0.0.1,3443 tcp from any to any 443 in

@m5m1th

This comment has been minimized.

Copy link
Owner Author

commented Apr 29, 2015

And for Yosemite:

/etc/pf.anchors/mindflash

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

Note: Trailing line break is important.

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
@nyukhalov

This comment has been minimized.

Copy link

commented May 12, 2017

Hi.
After applying that jenkins worked fine, but docker daemon which was installed on the same node got crazy: all http requests from a docker container got 404 Not Found. I suppose the requests were redirected to localhost for some reason and obviously could not be handled.

I'm on Ubuntu 16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.