Dynamic DNS with No-IP on Debian

With all my other tutorials on setting up mail and web servers, I figured it only makes sense to write up a tutorial on setting up a Debian installation with a dynamic DNS client. Usually your home router has one IP that usually changes from time to time. Using a dynamic DNS client, in this case with No-IP, we can setup Debian so that it will automatically update your DNS records when your IP changes. I decided to use No-IP because they’re one of the dynamic DNS providers that still offers a free account, this is useful if you’re just learning and aren’t quite ready to purchase a domain.

Secure the domain

The first thing you need to do is secure the domain either by means of creating a free account or purchasing a domain with No-IP. From the Hosts/Redirects tab, under Manage Hosts you’ll want to click Add a host if you haven’t already. You should probably set the IP for the domain initially. You can do this by making sure that DNS Host(A) is selected and then typing your IP in. By default No-IP will automatically default this value to whatever the external IP is of the system you’re browsing the website with.

Install the No-IP client

The next step is downloading and installing the No-IP client that will update your DNS with your dynamic IP. Note, if you have several machines all behind the same external IP then you really only need to install the No-IP client on one of your servers. So we’ll run a few commands to download the client, unpack it, build it, and install it.

wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz
tar xzf noip-duc-linux.tar.gz
cd noip-*
sudo make
sudo make install

Upon running the final command you should be presented with some configuration questions. The first two will ask you for your No-IP username and password. After you’ve entered your credentials the installer will tell you how many hosts (domains/subdomains) you have available and if you’d like to update them all. If you select No it will go through each host and allow you to pick which ones you’d like to update.

After you’ve made your selections it will ask for an interval (in minutes). This controls how often the service will check to see if your IP has changed. 30 is a good default value, if you know that your IP changes more frequently then you may want to lower this value.

The final question will ask you if you’d like to run a program upon completing a DNS update. Most people can go ahead and say Nohere.

Now we just need to create an init script that will automatically start the service when Debian boots. As root, copy the following bash script and save it to /etc/init.d/noip2.

#######################################################
#! /bin/sh
case "$1" in
        start)
                echo "Starting noip2."
                /usr/local/bin/noip2
        ;;
        stop)
                echo -n "Shutting down noip2."
                killall -q -TERM /usr/local/bin/noip2
        ;;
        *)
                echo "Usage: $0 {start|stop}"
                exit 1
esac
exit 0
#######################################################

Next we need to modify the permissions on the script so that it’s executable and add the service.

sudo chmod 755 /etc/init.d/noip2
sudo update-rc.d noip2 defaults

Go ahead and restart your installation and the No-IP service should now be running.

Port Forwarding

One more important thing to note is that if your servers aren’t directly mapped to an external IP, meaning they have a local address (e.g. 192.168.x.x) and pass traffic through a router, then you’ll need to setup port forwarding on your router so that the proper traffic makes its way to your appropriate servers. Note, you only need to setup port forwarding if you want your server(s) to be available via the internet. Here are some common ports you may need to forward for certain functions.

  • TCP port 53 (DNS) – If you run an authoritative nameserver you’ll need this
  • TCP port 25 (SMTP) – Required for a mail server, the server receives mail on this port
  • TCP port 80 (HTTP) – Required for a web server, allows you to serve web pages
  • TCP port 143 (IMAP) – Required if you want to download your mail from your server over the internet using a desktop client like Thunderbird or Outlook
  • TCP port 443 (HTTPS) – Required if you want to serve secure web pages using SSL

Update: Fixed init.d script

I updated the init.d script as killproc is no longer relevant and needed to be replaced by the killall command.