Hosting At Home on DHCP with Comcast

So you have a Comcast connection as home and you want to run a server? The problem is your IP Address is  DHCP (Dynamic Host Configuration Protocol) assigned so it is constantly changing. In order to do this I will be assuming two things: 1) you are using linux on the server you want to setup as your local web server and 2) you already have your domain name registered from somewhere like godaddy.com. Once your domain is registered, you will also need to make sure to set your DNS records to point to ns1.everydns.net, ns2.everydns.net, ns3.everydns.net, and ns4.everydns.net.

If you have these in place, we are ready to move on.

The next step is to set up an account with everydns.com. It’s free. And you can route multiple domain names from a single account. However, they will all point to the same server. This wont matter because all you need is one. To configure the domain so that the routing works correctly, you must select the “Make domain dynamic” option. This will allow you to send updates through the API to update your local DHCP address as it changes.

Now you need to add your IP address. Not sure what it is? No problem, you can visit whatismyip.com and it will tell you. Once you set it all up, you are now ready to configure your server.

There are two things you will need to do to make sure your everydns.com will route correctly to your server. You will need to set up a .sh script that will talk to the everydns.com server and you will have to set up a cron job to run the update. Never done it before? No worries, I will walk you through it.

First, you will need to setup the script. Here is what you need:


#!/bin/sh
# extract wan IP address...
EXTIP="`wget www.whatismyip.com/automation/n09230945.asp -O - -q`"

# Old IP address to compare
PASTIP="`cat /root/pastip.txt`"

# Capturing local date and time for log timestamp
CURDATE="`date`"

if [ "$EXTIP" = "$PASTIP" ]
then
echo "DNS is current already up-to-date"
else

#Placing new IP in local file
echo "$EXTIP" > /root/pastip.txt

#  Creating a log of ip changes
echo "DNS has been updated to your current IP   $CURDATE" >> /var/log/dns.log

#--------snippet----------------change according-----------
USERNAME="YOUR_USERNAME_HERE"
PASSWORD="YOUR_PASSWORD_HERE"
DOMAIN="YOUR_DOMAIN_NAME_HERE"
URL="http://dyn.everydns.net/index.php?ver=0.1&domain=${DOMAIN}"
/usr/bin/wget --quiet --http-user=${USERNAME} --http-password=${PASSWORD} \
-O - ${URL} | tee /tmp/dynamic-dns.txt | grep -q 'IP change suceeded'
#--------snippet----------------

fi
#Script End

On the machine you want to use as the server, you will need to create a file called dns.sh. If you are not familiar with how to do this, here are the steps:

  • First, you need to make sure you have root access. From the shell you can type sudo su and it will prompt you for your password. Once you enter your password, you are now root.
  • Then you create the file as by using the following command: vi /root/dns.sh
  • Once you are in the file, press the letter i and you are now in insert mode. Copy and paste the above script to the file. Make sure if you do not know how to use vi that you change the username, password, and domain name in the script before you paste it. Then hit the ESC key once, type :wq and hit enter. The file is saved.
  • Now you need to setup the cron job that will run this script every few hours to check your current IP address and report it to everydns.com. You do that by typing: crontab -e and press enter.
  • Paste the following information using the same vi commands listed above (press i, paste the information, hit ESC, then type :wq and hit enter). The command you will be pasting is:
    3 0,2,4,6,8,10,12,14,16,18,20,22 * * * /root/dns.sh

Now you are ready. Your server is online and you should be able to connect to it over the internet from anywhere. One other thing to mention, is that you can see the updates in the following file: /root/pastip.txt because the cron tracks the updates every time it runs.

Hopefully if you are doing this, you at least have some idea of how to run Linux and keep things up and running. As always, if you are having troubles, post a comment and I will do what I can to help.

Happy coding!

Like it? Post to your favorite location and share.
  • Digg
  • del.icio.us
  • Facebook
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Twitter

Leave a Comment

You must be to post a comment.