Created
March 21, 2015 18:08
-
-
Save jsonfry/b9e9ba2cab805be66b37 to your computer and use it in GitHub Desktop.
Ubuntu: Redirect Local Ports
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
sudo iptables -F -t nat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.