Showing posts with label iptables. Show all posts
Showing posts with label iptables. Show all posts

Thursday, April 14, 2011

Port Forwarding

The post is more for my own remembering than anything else, although I'm posting it here just in case someone stumbles across it and finds it useful

The goal: allow a remote computer to view a website hosted on my local computer.
Steps:
  1. Set up an account with dyndns.org
  2. Install ddclient on my Ubuntu machine to periodically notify dyndns.org what my IP address is
    1. Don't prepend "http://" to your domain name in the ddclient setup!
  3. On my router, assign my computer a static IP address
  4. On my router, forward incoming traffic on port 8080 to the new static IP address
  5. On my computer, port-forward port 8080 to port 80, where my apache webserver is listening
    1. sudo iptables -t nat -A PREROUTING -p tcp --dport 8080 -j REDIRECT --to-port 80 (add the port forwarding rule)
    2. sudo iptables -F (flush the rule)
    3. sudo iptables -t nat --list (view the rule)
    4. sudo bash -c "iptables-save < /etc/iptables.rules" (save the rule to a file)
    5. sudo echo -e '#!/bin/sh\niptables-restore < /etc/iptables.rules\nexit 0' > /etc/network/if-pre-up.d/iptablesload (to create a script to restore the iptable rules every time the network interface comes up)
    6. sudo chmod +x /etc/network/if-pre-up.d/iptablesload (to make the script executable)
  6. Visit my site in a browser at http://subdomain.dyndns.org:8080
iptables: https://help.ubuntu.com/community/IptablesHowTo