DNS + DDNS + nsupate for dynamic IP web hosting on Debian mini-HOWTO

If you hope to host a static domain name, the process is quite straight forward: find a DNS provider, pay and register, provide 2 DNS server that will contain your domain information, and that's all. This shouldn't be a problem if you have 3+ static IP, so at least 2 for DNS server plus other for normal mapping. Well, as a normal Linux system administrator, this should be part of your daily jobs.

But what will happen if you don't have static IP? The case will be more complicated since you can't provide the required 2 static DNS server for redirect, and so the domain registration can't complete.

At this moment, you may think about free DDNS service, e.g. No-IP, DynDNS and so on. BTW, usually they only provide some free domain with not friendly DNS suffix (e.g. no-ip.info, no-ip.net, etc), which usually not your cup of tea...

So how to overcome these difficulties? Just combine both DDNS (take No-IP service as example), bind9 and nsupdate together. So finally, you will have a system with:

  1. Real DNS hostname. You will need this from anyone of DNS service provider; and for sure, you will able to register any name as you like if available.
  2. DDNS hostname for request redirect. This is just a fake name, in order to fake DNS service provider, and point the DNS NS request to our DDNS server.
  3. A Debian server that running bind9, noip2 and nsupdate. We will use the nsupdate toolkit to update our own bind9, about our current public IP. So this is a loop-back hack for bind9.

Sounds so tricky? Just take it easy, and I will guide you step-by-step :)

Register both DNS and DDNS hostname

As mentioned above, the DDNS hostname is for redirect fake, so just free feel to register ANY 2 name as you like from ANY free DDNS provider.

I will use example1.redirectme.net and example2.redirectme.net from No-IP, for a demo domain example.com though this HOWTO.

In case of No-IP, you may hope to form these 2 fake DDNS name as group. If you do so, the follow up action for setting up No-IP client will be much simple. Trust me, form them into a group :)

Moreover you will need to register a real DNS hostname from ANY DNS service provider. Usually they will provide something call "domain name parking", and so you will able to register a domain even you don't hae 2 static DNS server on hand. I will not mention the detail, and please follow their guideline.

I will use a demo domain example.com though this HOWTO.

Setup No-IP client (no-ip or noip2)

So let's move to the next section. You will need to install noip2 (or no-ip) package from Debian. Jut simply run:

apt-get install no-ip

or (for a newer version of no-ip client from Debian):
apt-get install noip2

The installer will ask you some question about your No-IP username, password and so on. Provide required information, and so your No-IP client will take action to update your public IP to No-IP servers.

Now No-IP will know your current dynamic IP, by example1.redirectme.net and example2.redirectme.net. Go to www.no-ip.com, login and check if it is now pointing to your server?

Configure Real DNS hostname

Now let's back to your real DNS service provider. Log into their page, and place those 2 fake DDNS hostname (in this case, example1.redirectme.net and example2.redirectme.net) as the required static DNS servers. Yes, the DNS service provider expect for static IP, but now we provide DDNS hostname. Don't care about this, they will able to function :p

Install and configure bind9

For Debian, the installation of bind9 is very simple and straight forward. Just run:

apt-get install bind9

I will assume you know how to setup normal static IP domain with bind9. There is a lot of document all around Internet, and so I will not mention the detail in here. But here is the tricky part: just setup some basic domain information, e.g. MX, NS and CNAME, but leave the A blank. That's means your domain configure file may have similar layout, and that's all:

$ORIGIN .
$TTL 38400      ; 10 hours 40 minutes
example.com         IN SOA  example.com. root.example.com. (
                                2008030501 ; serial
                                10800      ; refresh (3 hours)
                                3600       ; retry (1 hour)
                                604800     ; expire (1 week)
                                38400      ; minimum (10 hours 40 minutes)
                                )
                        NS      ns1
                        MX      10 mail1

Install and configure nsupdate

Therefore where can we obtain the A information (which means our server's dynamic IP)? And this is the time for nsupdate. nsupdate is a dynamic DNS update utility for bind9. To install it under Debian, run:

apt-get install dnsutils

Here is a complete guideline for nsupdate and so I will not duplicate within this HOWTO. Just a simple example in here:
cd /etc
dnssec-keygen -a HMAC-MD5 -b 128 -n HOST ns1.example.com.

The key point is how to setup the script file, in order to link all service together. Here is my example:
#!/bin/sh
IPADDR=`ifconfig eth0 | grep 'inet addr:[0-9]' | tr -s " " | cut -d" " -f3 | tr -d "addr:"`
echo "server localhost" > /tmp/nsupdate
echo "zone example.com" >> /tmp/nsupdate
echo "update delete ns1.example.com. A" >> /tmp/nsupdate
echo "update delete ns1.example.com. CNAME" >> /tmp/nsupdate
echo "update add ns1.example.com. 38400 A $IPADDR" >> /tmp/nsupdate
echo "update add *.example.com. 38400 CNAME ns1.example.com." >> /tmp/nsupdate
echo "show" >> /tmp/nsupdate
echo "send" >> /tmp/nsupdate
echo "" >> /tmp/nsupdate
/usr/bin/nsupdate -k /etc/Kns1.example.com.+157+09828.private -d /tmp/nsupdate

So some tricky point:
  1. Line 1: Since we have IPv6 on modern Linux, you will need this syntax to figure out your current public IP.
  2. Line 2: We will point to localhost as our update target. As mentioned at beginning, this is a loop-back hack for bind9.
  3. Line 6: A demo update command for A.
  4. Line 7: A demo update command for CNAME. More tricky that we alias ANY OTHER SUB-DOMAIN to this server by *.

Create this script file as /etc/init.d/udpate.ns1.example.com (or some else name as you like), change file mode as 755 (chmod 755 /etc/init.d/udpate.ns1.example.com), and run it during system bootup with:

update-rc.d -f udpate.ns1.example.com defaults 99 01

Check you setup after successful update

After a complete and successful update with nsupdate, you domain file should have similar layout as below (for sure, you will have a different IP for ns1):

$ORIGIN .
$TTL 38400      ; 10 hours 40 minutes
example.com         IN SOA  example.com. root.example.com. (
                                2008030501 ; serial
                                10800      ; refresh (3 hours)
                                3600       ; retry (1 hour)
                                604800     ; expire (1 week)
                                38400      ; minimum (10 hours 40 minutes)
                                )
                        NS      ns1
                        MX      10 mail1
$ORIGIN example.com.
ns1                      A       10.0.0.1
*                       CNAME   ns1

Run nslookup or dig to check from remote host. You should get it done :)


DynDNS Server

Susanne Ledermüller's picture

Any idea how to run an own server instead of only a client?

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <h1> <h2> <h3> <h4> <h5> <h6> <em> <strong> <code> <del> <blockquote> <q> <sub> <p> <br> <ul> <ol> <li> <dl> <dt> <dd> <a> <b> <u> <i> <sup> <acronym> <pre> <img>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Images can be added to this post.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.