Recently set up ddns (dynamic DNS) for my Linux workstation successfully. The general intention for ddns is to allow remote access to the workstation where there is no static IP but dynamic IP from DHCP. A lot of ISPs provide the domain and ddns service either for free or not. In my implementation, I have bought a domain from domain.com (yep, this is not free) and used the ddns service from he.net (yes, it is free!). Anyway, hope this post could give some hints for the newbies, like myself.
0. If you want your own domain name…
This may be the first thing we need to make it clear. Actually, there are some ISPs providing the free domain and ddns the same time. For sure, the domain is kind of subdomain of the ISP, like yourTargetDomain.DomainOfISP. If you decide to choose the free the domain as well as the ddns from the ISP, then please follow the detailed instruction from that ISP and refer to the ddclient down there maybe for your reference.
1. Get your domain
Get your target domain for any ISP. For instance, I have bought the domain ‘daveti.me’ from domain.com. After you bought the domain, you should be able to login your account and find the settings for that domain, like DNS, nameserver, FTP, mail. and etc. We will need some changes here later for ddns configuration. But not now…
2. Get the dynamic DNS service
Find what ever ISP you want, which provides the ddns service, either for free or not. Here, I choose he.net, which is free! After the quick registration, please click the free DNS, where you could find the detailed instruction on the features provided by he.net, as well as some configuration example.
3. Configure the ddns on dns.he.net
After login, you will be asked to add a new domain name into your ‘Zone’. Yes, we will add the newly bought domain there. Then click ‘edit’ for the newly added domain, you will find few entries added for the domain with different nameservers, like ‘ns1.he.net’, ‘ns2.he.net’…Remember all the names of these nameservers. We will use them later. Then, please click ‘New A’ above, which will create an A record used for IPv4 address query during DNS analysis. Put the same domain name as the name of the A record; put your current IPv4 address (ifconfig -a for Linux, ipconfig /all for Windows) into the address field; set the the TTL to be the minimum value, like 5 min ~ cause we are using DHCP instead of static IP; choose the ‘enable dynamic dns’ feature – again, we want ddns, right? The same stuffs happens for the AAAA record, which is used for IPv6 address. You need the same name for the record and put your current IPv6 address there, as well as the same TTL and ddns enabling. Once it is done, you will find the 2 newly added entries in the domain management window, as well as the nameservers mentioned before. Click the DDNS column in the A record, generate the ‘key’ and submit. Note, save the key here! Click the same field in the AAAA record and use the same ‘key’ and submit.
After the dns.he.net configuration, you should save the names of the nameservers and the name and the key used in both the A record and AAAA record. NOTE: both the name and the key are eventually the same for the 2 records!
4. Reconfigure the domain
Let’s come back to your domain ISP, where we need to change the nameservers for our domain. The default nameservers should be provided by your domain ISP. But for ddns, we need to use the nameservers provided by the ddns ISP, like he.net. Remember the names of nameservers we have saved before? Let’s remove the default ones and add our ddns enabled nameservers.
So far, both the domain and ddns services are ready now, which means given the DNS query for our domain, the nameserver would return the right IP address. The only problem is how could we update the IP address within the nameserver. There are a few client tools which are able to do this job. We will use ‘ddclient’ here, which is kind of standard choice under Linux and is supported by he.net the same time. After downloading and installation, we need to configure the ddclient.conf under /etc adding support for dns.he.net
# Hurricane Electric
protocol=dyndns2 # default
use=if # use the eithernet card (to get the current IP)
if=em1 # use certain interface (ifconfig -a, to get the current IP)
server=dyn.dns.he.net # default
login=daveti.me # the name of the A/AAAA record
password=adfadfa # the key of the A/AAAA record
daveti.me # the domain name
After the configuration, all we need to do is to start the ddclient service – just run ‘ddclient’. You will find the the ddclient service keeping running when ‘ps -ef | grep ddclient’.
6. Make it perfect
Till now, if we are lucky enough, we have done all the configuration for ddns. Moreover, we want to make things perfect. So we will try to change the hostname of the machine to the new domain name and add the ddclient service into the the startup of our machine. The way to change the hostname permanently in Fedora Linux is to add new domain name into /etc/hostname and add new line ‘HOSTNAME=domainName’ into /etc/sysconfig/network. The way to start ddclient when the machine is up is to add ddclient into the ‘startup application’ via ‘system->preference’ in Gnome desktop.
7. Some commands
We will list some commands examples here for DNS related debugging.
dig ns domainName
dig a domainName +short
dig aaaa domainName +short