Dynamic DNS—an Object Lesson in Problem Solving

The other day in the Linux Journal IRC room (#linuxjournal on Freenode), I was whining to the channel about no-ip.com deleting my account without warning. My home IP address hadn't changed in a couple months, and because there was no update, it appeared abandoned. The problem was, although the IP address hadn't changed, I was using the Dynamic DNS domain name to connect to my house. When the account was deleted, the domain name wouldn't resolve, and I couldn't connect to my house anymore.

The folks in the IRC channel were very helpful in recommending alternate Dynamic DNS hosting services, and although there are still a few free options out there, I was frustrated by relying on someone else to manage my DNS services. So, like any nerd, I tried to figure out a way to host a Dynamic DNS service on my own. I thought it would be a simple apt-get install on my colocated server, but it turns out there's not a simple Dynamic DNS server package out there—at least, not one I could find. So, again like any particularly nerdy nerd, I decided to roll my own. It's not elegant, it's not pretty, and it's really just a bunch of cheap hacks. But, it's a great example of solving a problem using existing tools, so in this article, I explain the process.

First, it's important to point out a few things. The purpose of this article is not really to explain the best way to make a self-hosted Dynamic DNS system. In fact, there probably are a dozen better ways to do the same thing. That's sort of the point. The more familiar you are with Linux tools, the more resourceful you can be when it comes to problem solving. I go through the steps I took, and hopefully most readers can take my method and improve on it several times over. That type of collaboration is what makes the Open Source community so great! Let's get started.

My Particular Toolbox

We all have a slightly different bag of tricks. I'm in the "extremely lucky" category, thanks to Kyle Rankin tipping me off about the free Raspberry Pi colocation service. A full-blown Linux box with a static IP on the Internet is truly the sonic screwdriver when it comes to these sorts of things, but perhaps someone else's solution won't require a complete server.

Along with the Raspberry Pi server, I have a Linux server at home, a home router and a handful of domains I own. I also have accounts on several Web hosting servers, and accounts with cloud-based storage like Dropbox, Google Drive and a handful of others.

First Problem—What's My IP?

The beauty of Dynamic DNS hosting is that regardless of what your home IP address is, the same domain name will resolve even if it changes. Granted, my home IP address hadn't changed for months, but I still used the DNS name to access it. Therefore, when my account at no-ip.com was deleted, I had no way to tell what my home IP was.

There are plenty of sites on the Internet that will return your IP address. Because I just had my Dynamic DNS account deleted, I really didn't want to depend on a free on-line service for detecting my IP address. Thankfully, this piece of the puzzle was simple. A few lines of PHP hosted on any Web host that supports PHP is all it takes. For example, my IP detection script is hosted at http://snar.co/ip (my personal domain—feel free to use it). See it in action in Figure 1. It contains nothing more than this:

// Save the IP to a variable
$ip_address = $_SERVER['REMOTE_ADDR'];

// To display the IP:
echo $ip_address;

Figure 1. Unlike many "what is my IP" services, my script returns nothing but an IP address.

The frustrating part is that although I had a way to detect my IP address at home, I wasn't actually at home, so I had a catch-22 situation. Thankfully, my wife was home. I texted her and asked her to visit my snar.co address and let me know the IP address she got back. Once I had that IP address, I could connect to my home server and set up some automation.


Shawn is Associate Editor here at Linux Journal, and has been around Linux since the beginning. He has a passion for open source, and he loves to teach. He also drinks too much coffee, which often shows in his writing.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

No-IP Free Dynamic DNS

Anonymous's picture

Yeah, I understand your frustration with your Free http://www.noip.com No-IP account getting deleted, but don't they have to pay to keep the lights on?

Their http://www.noip.com/free/ free dynamic DNS service has always worked flawless for me, especially since it is a free service. They even give me awesome tech support when I need help.

All I Say Is Worth Share!

GeekSays's picture

You must have burned couple of your hours to compile this tutorial for us, and even-more many of your precious hours in achieving this workaround. I found this is very helpful for me.

Good content, I trust this is

zeennate's picture

Good content, I trust this is a good weblog about Wish to see refreshing content material next time. Thanks for sharing this publish with us. Keep it up. voyance serieuse par mail

This has been wonderfully

ocim's picture

This has been wonderfully open-handed with people like you to present without restraint precisely what many individuals could have marketed as an e book to help make some money for their own end, and in particular since you could have tried it in the event you desired
kata kata motivasi

Sorry from No-IP

No-IP's picture

We apologize that your account was deleted. We do this monthly maintenance to keep our network clean and up to date. We have over 15 million users worldwide, so we like to keep only currently active hostnames on our system... We offer Enhanced Dynamic DNS that is only $14.95 a year and that will disable the 30 day activation... Just a thought.

free dyndns

insider's picture

I personally use free cloudflare DNS services.
Cloudflare also has good API to change params usng POST queries

So you can simply edit your A record by issuing curl command every time your IP changes.

I once had a better way I

Anonymous's picture

I once had a better way I wrote a program to check my inbox I have various subject tags


send ip
ping x.x.x.x
trace x.x.x.x

the program would check my email, and if it had various tags as above (I had more) it would execute and send en email response with the outcome. used this while on the road it worked out great :)


Dynamic DNS

Algot Runeman's picture

Instead of just reporting back the IP to the home server, I added php code to write the ip to a text file at the remote hosted server and then included that into a web page so it was a link. Now I just go to that web page and from there to the home server.

BASH script to log IPs on public web server

Mario Chamorro's picture

As Ralph Loizzo also posted , here is a scriptlet which I call '/bin/whip' . This visits my own public website via an hourly cron job and logs the IPs on all gateway interfaces by visiting non-existent "/ipaddress-IP-iface-IP" like so: - - [22/May/2013:09:59:09 -0400] "GET /ipaddress-home.example.com-eth0- HTTP/1.1" 404 1226 "-" "Wget/1.13.4 (linux-gnu)"

It will mail you when the IP changes . I call it 'whip' because I have another alias named 'ship' which SHows IPs on the local machine . 'whip' is the Web How IP . Here's the script:

# ---------

# -
# web / show IP : Mario Chamorro
# -
DEVLIST=`ls /proc/net/dev_snmp6`;
for DEV in $DEVLIST;
IP_ADDR=`/sbin/ip addr show dev ${DEV} | grep ${DEV}$ | awk '{ print $2 }' | cut -d/ -f 1`;
[ -z $IP_ADDR ] || wget -q http://${REMOTESERVER}/ipaddress-${LOCALSERVER}-${DEV}-${IP_ADDR}
# - mail if a new IP address is detected
[ -z $IP_ADDR ] || echo $IP_ADDR >> $FILEBASE.$DEV.txt
[ -r $FILEBASE.$DEV.txt ] && DIFFERENT=$( tail -n 2 $FILEBASE.$DEV.txt | uniq -c | wc -l ) || DIFFERENT=0;
[ $DIFFERENT -eq 2 ] && echo "New Home Gateway IP: $DEV:$IP_ADDR" | mail -s "New Home Gateway IP: $DEV:$IP_ADDR" $RECIPIENTS
# ---


Charles Snider's picture

Seriously, DynDNS is the easiest route. Just open a free account (or paid for that matter, it's only a $20 a year), plug your account info into your router, and viola, just a hostname to remember. Automatically updated when your IP changes.

Not free anymore

Chuck's picture

DynDNS doesn't have a free option anymore. If you had a free account with them before you're grandfathered in but they harass you monthly to try to get you to sign up for their paid services.

DynDNS not free-- wrong

GCL's picture

It happens that you're wrong. They do so provide that free account. Yes they do want people to sign up for the paid service, but in actuality all they ask for is that people to sign-in once a month into their account to confirm that it exists.

I've had mine for several years, and that particular issue was not part of the whole issue. All they want is what I've stated.


Chuck's picture

...you didn't read my post above. If you signed up years ago for a free account with DynDNS, you were grandfathered in and can continue your free account by logging in to their web site once a month (I do). But if you go to http://dyndns.com today, you will NOT find an option to sign up for free DNS service now -- it doesn't exist.

Reply to comment | Linux Journal

kredit mobil toyota's picture

Terrific article! This is the type of info that are meant to be shared across
the web. Disgrace on Google for not positioning this post higher!
Come on over and seek advice from my site . Thanks =)

All the articles you talked

ibaikal's picture

All the articles you talked about inside post are extremely good and is very helpful. Let me maintain it in mind, thanks for expressing the information retain updating, excited to get more articles.


markc's picture

If you happen to run your own Bind nameserver on a remote host somewhere then this will work...


Keeping track of IP address

Jon TuxTweaks's picture

While I do have a remote web server I could use, I chose to extract my IP from the configuration page on my modem. A cron job checks it every 10 minutes and if it changes then it sends me an email with the new IP.

This may be useful for those without access to a static IP server. You can find my full writeup on my blog : http://tuxtweaks.com/2012/12/keeping-track-of-my-ip-address/

Roll your own dynamic dns

Ralph Loizzo's picture

I have a web site hosted out on the Internet . Every hour my server at home attempts a wget to the remote webserver to a bad filename. My server then checks the error log for the remote ip. If it changes, it changes the DNs entry for my home server. 6 years no problems