Skip to content

Instantly share code, notes, and snippets.

@logicalparadox
Created March 20, 2012 23:44
Show Gist options
  • Save logicalparadox/2142595 to your computer and use it in GitHub Desktop.
Save logicalparadox/2142595 to your computer and use it in GitHub Desktop.
Getting Node.js process to run on port 80 without sudo
# NAT interface routing
*nat
# Setup
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [2:128]
:OUTPUT ACCEPT [2:120]
:POSTROUTING ACCEPT [2:120]
# Redirect port 80 to port 8080
-A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
# Redirect port 443 to port 9090
-A PREROUTING -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 9090
# Save
COMMIT
# Filter interface routing
*filter
# Setup
:INPUT ACCEPT [2:128]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [246:28805]
# Allow all internal traffic
-A INPUT -i lo -j ACCEPT
# Accept already established connections
-A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
# Our exposed ports
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
# Save
COMMIT
# save to /etc/iptables.rules
# $ sudo iptables-restore < /etc/iptables.rules
#!/bin/sh
# save this to /etc/network/if-pre-up.d/iptaload
iptables-restore < /etc/iptables.rules
exit 0
#!/bin/sh
# save this to /etc/network/if-post-down.d/iptasave
iptables-save -c > /etc/iptables.save
if [ -f /etc/iptables.downrules ]; then
iptables-restore < /etc/iptables.downrules
fi
exit 0
@logicalparadox
Copy link
Author

Also,

chmod +x /etc/network/if-post-down.d/iptasave
chmod +x /etc/network/if-pre-up.d/iptaload

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment