Skip to content

Instantly share code, notes, and snippets.

@jsonfry
Created March 21, 2015 18:08
Show Gist options
  • Save jsonfry/b9e9ba2cab805be66b37 to your computer and use it in GitHub Desktop.
Save jsonfry/b9e9ba2cab805be66b37 to your computer and use it in GitHub Desktop.
Ubuntu: Redirect Local Ports
# Run these commands, and use the files below for the content
sudo nano /etc/network/if-up.d/my-redirect
chmod +x /etc/network/if-up.d/my-redirect
nano /etc/network/if-down.d/my-redirect-clearer
chmod +x /etc/network/if-down.d/my-redirect-clearer
#!/bin/bash
for i in $(sudo ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'); do
sudo iptables -t nat -I PREROUTING 1 -d $i -p tcp --dport 80 -j DNAT --to $i:8080
sudo iptables -t nat -I PREROUTING 1 -d $i -p tcp --dport 443 -j DNAT --to $i:8443
done
#!/bin/bash
sudo iptables -F -t nat
@jsonfry
Copy link
Author

jsonfry commented Mar 21, 2015

Useful for forwarding / redirecting things like Jenkins and Jira from port 8080 to the normal http port 80, when you don't want to run an apache / nginx proxy.

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