One of the things I use my vServer for is some sort of dyndns service. I need my home computer to be accessible from the outside without knowing it’s dynamic IP address. In this article, I will describe briefly how you can reach that. You will need some sort of own webserver with at least a static IP address and you need to be able to edit the zone file of one of your domains. Also, you should know what a zone file is or dig into it, before you start. What I basically did is the following: I installed a DNS server on my vServer and set the subdomains *.SUB.DOMAIN.TLD to be redirected to my server. When the main DNS server encounters a request to one of those sub-sub-domains, it will redirect it to my server and thus allow me to answer dynamically with my home computer’s IP address. Throughout the article I will use the above scheme for the domains, that you will want to edit to fit your purposes: PC.SUB.DOMAIN.TLD, where DOMAIN.TLD is some domain you own and are able to edit the zone file for, SUB is some subdomain to chose for your DNS namespace and PC would be the identifier of your computer at home. (You can choose this arbitrarily).

Set up a DNS server

I must say, that I don’t know exactly anymore, what I did. I believe after installing the named daemon, bind9, I only edited /etc/bind/named.conf.local and added the following:

        type master;
        file "/etc/bind/zones/";
        allow-update { key "rndc-key"; };
        notify yes;

Then, create /etc/bind/zones/db.SUB.DOMAIN.TLD and insert your desired zone file code, for example:

$TTL 86400      ; 1 day
                                2001072085 ; serial
                                10800      ; refresh (3 hours)
                                3600       ; retry (1 hour)
                                1814400    ; expire (3 weeks)
                                86400      ; minimum (1 day)
                        NS      SUB.DOMAIN.TLD.
                        A       YOUR.SERVER.IP.ADDRESS
PC                     A       YOUR.HOME.IP.ADDRESS

Replace PC, SUB.DOMAIN.TLD, EMAIL.DOMAIN.TLD, YOUR.SERVER.IP.ADDRESS and YOUR.HOME.IP.ADDRESS with the appropriate values. (The last one is the line we will constantly be updating) As described above, your home computer will then be reachable with PC.SUB.DOMAIN.TLD.

Redirect SUB.DOMAIN.TLD to your server

As I said, you need access to the zone file of DOMAIN.TLD. If you have, just insert this line:

SUB                      IN NS      YOUR.SERVER.IP.ADDRESS

replacing SUB with what you want to use as a subdomain and YOUR.SERVER.IP.ADDRESS with the IP address of your server. It will take a while for the DNS servers to update the zone.

Create the update scripts

To make your server aware of a change of your IP address, you have to tell it whenever you reconnect to the internet and are assigned a new IP address. We thus create two scripts in /etc/bind/zones/:

  • updatescript

    # usage:  do-nsupdate [text-file-containing-nsupdate-instructions]
    nsupdate -y "rndc-key:YOUR_RNDC_KEY" -v $1
  • updatefile

    server SUB.DOMAIN.TLD
    update delete PC.SUB.DOMAIN.TLD A
    update add PC.SUB.DOMAIN.TLD 86400 A

Replace YOUR_RNDC_KEY with the secret value in /etc/bind/rndc.key and edit the updatefile according to your data.

Replace the IP address and run the updatescript

You will now need the following, and I will leave it up to you how you do this. (I would be glad about nice solutions in the comments!) Whenever you reconnect to the internet (there are hooks for WICD, NetworkManager etc. that you can use), update the in /etc/bind/zones/updatefile with your home computer’s new IP address and run /etc/bind/zones/updatescript /etc/bind/zones/updatefile and your zone file will be updated.

I myself solved this with a small PHP script, reading out the requester’s IP address and then updating and running the DNS update:

$upd = "sed -i 's/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/" . $ip . "/g' /etc/bind/zones/updatefile";
system("/etc/bind/zones/updatescript /etc/bind/zones/updatefile");

However, there certainly are nicer solutions involving just one request. One can, for example, read out the IP address when using an SSH request and then just execute the above commands over SSH. This would be more elegant than my solution.

The hook for WICD would be placed on your home computer in /etc/wicd/scripts/postconnect/ and will be executed after successfull connection to the internet. NetworkManager stores it’s hooks in /etc/NetworkManager/dispatcher.d. You have to google to find the appropriate way to use these hooks.


I hope I could be a bit helpful, and at least make clear how you can use your own server to act as some Dyndns-like service. If you succeed in setting the service up following my guidelines and/or if there is something missing here, I would be glad about a comment.

<section id="comments" class="comment-list"><h1>Comments</h1><ul> <li class="comment"> <div class="head"> <span class="author">robert</span> <span class="date">May 30, 2013, 8:26 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-161">reply</a> </span> </div> <div class="text"><p>hey good tutorial,</p> <p>but, is here a setup , to use pc.domain.tld ?<br /> also <br /> dyn1.domain<br /> dyn2.domain ???</p> <p>i serve my domains self but tryed alrdy alot of configs that dont work :(<br /> would be great to know</p></div> </li> <li class="comment"> <div class="head"> <span class="author">oli</span> <span class="date">June 3, 2013, 9:50 a.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-162">reply</a> </span> </div> <div class="text"><p>Hi robert, I am not too familiar with zone files and bind. It should be possible, by having multiple <code>zone</code> entries in your named.conf.local file. </p></div> </li> <li class="comment"> <div class="head"> <span class="author">Matt</span> <span class="date">Dec. 16, 2014, 7:30 p.m.</span> <span class="actions"> <a href="#" class="add-reply" id="comment-240">reply</a> </span> </div> <div class="text">&lt;p&gt;Thanks for sharing this. I have not tried it as I wanted to use something lighter than bind9 on my low end VPS. However, I did notice an issue: you can’t have an IP address in a NS record, but you could do something like this to get round it:&lt;/p&gt; &lt;p&gt;SUB IN NS NS.DOMAIN.TLD&lt;br/&gt; NS IN A YOUR.SERVER.IP.ADDRESS&lt;/p&gt;</div> </li> </ul></section>

Write comment