The scenario is the following: You are behind your home network, usually controlled by a wireless router which connects to the internet, and you want to get access from outside of your network, let’s say to access both of your http and ssh, in a specific machine of the LAN.

  1. If there are more then one machine in the network which needs to be seen from the outside, then configure your http and ssh daemons to run on a specific ports - a different one for each machine. I like to use the default port with a suffix of two numbers that are easy to remember... let's say ssh: port 2269, http 8069. Usually you need to edit the config files, for instance:
    /etc/ssh/sshd_config
    and
    /etc/apache2/httpd.conf
    for ssh and apache respectively (config files might be on a different location depending on your distro - set them up accordingly).
  2. Enter your router admin page, and forward the ports specified above, for those in your machine (usually mac address is used to select the machine in the network).
  3. Check if it works by trying
    ssh localhost -p 2269
    and using your browser with
    http://localhost:8069
  4. That's the easy part. The next step is to keep track of the dynamic ip address as seen from the outside (assuming you don't have a static one).
  5. First you need to get the ip as seen from the outside. The website whatismyip.com provides a service for automation processes. Then you need to export it to an accessible machine. The following script does the task (I assume you have the ssh authorization keys setup on both client and server machine, if you don't, google how to do it):
    updateip.sh
    #!/bin/bash
    
    IPADDRESS=`wget www.whatismyip.com/automation/n09230945.asp -O - -q`
    echo $IPADDRESS > /tmp/ipaddress.tmp
    echo "Last update on: " `date`  >> /tmp/ipaddress.tmp
    scp -B -i /home/myuser/.ssh/id_dsa  /tmp/ipaddress.tmp  remoteuser@remotemachine.com:~/public_html/
  6. Test if it works, by making it executable and run it on the command line.
  7. If it does, than yay! Now let's make it automatically by creating a cron task (I use vixie-cron) to execute the
    script above every 10 minutes:
    */10     *      *      *       *       /home/myuser/updateip.sh
    Note: If you don’t know how to use cron, check this.
  8. Add this cron to you crontab, reload it, and check if it's running with
    crontab -l
  9. Check if everything is working by peeking at
    www.remotemachine.com/ipaddress.tmp
    and check if the last update date is changing as expected.

There, done it.