Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Maintaining a Dynamic DNS automatically. Storage Devices
Dynamic DNS services provide you with a domain name you can use with a non-static IP address, like most home computers have. To use these requires some action to periodically contact the DNS server and let it know if your Dynamic IP address changed. Usually there are complicated scripts provided to do this, and MacOSXHints has published a few.

However one can greatly simplify this with a launchDaemon and a single built in OSX unix command.

First, this assumes that you have set up an account with a Dynamic DNS service. I use the free service provided by FreeDNS. One updates this simply by loading a web page URL. The act of making that page request alerts the DynamicDNS of your IP address and it updates.

Thus all we need is a LaunchDaemon that runs every hour that reloads that page. Here is an example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>dynamic_dns_updater</string>
	<key>Disabled</key>
	<false/>
 <key>UserName</key>
 <string>nobody</string>
	<key>StartInterval</key>
		<integer>3600</integer>
	<key>ProgramArguments</key>
	<array>
		<string>/usr/bin/curl</string>
		<string>--silent</string>
		<string>--insecure</string>
		<string>https://freedns.afraid.org/dynamic/update.php?YKIJUSiikf83kfj8dhfhuee9jdjd9ejfj99fj9jslRRRT</string>
	</array>
</dict>
</plist>
You will need to edit the above example an insert the key for your registered dynamic DNS account in the above string GET request. The one above is not for your site. You can find this at FreeDNS by simply manually refreshing your site online and then looking at the URL that it used. Other dynamicDNS services will have other URL structures that you need to query for the update.

You save this in the location:

/Library/LaunchDaemons/dynamic_dns_updater.plist

then load it:
sudo launchctl load /Library/LaunchDaemons/dynamic_dns_updater.plist
sudo launchctl start dynamic_dns_updater
And that's it. This will perpetually update your dynamic DNS whenever the computer is awake.

To remove it permanently:
sudo launchctl stop dynamic_dns_updater
sudo launchctl unload /Library/LaunchDaemons/dynamic_dns_updater.plist
rm /Library/LaunchDaemons/dynamic_dns_updater.plist
A few caveats on getting this to work. First, if you just download that plist file above, depending on how you do this, you may end up with some unwanted extended file attributes. The launch Daemon service won't run files with the wrong permissions or attributes. You can inspect these by listing the file like this:

ls -laeo@ /Library/LaunchDaemons/

if you see any below the file you can then manually delete these with the xattr command. For example, if there is quarantine from the download you can get rid of it like this.
sudo xattr -d com.apple.quarantine /Library/LaunchDaemons/dynamic_dns_update.plist
The plist should be owned by root:wheel.

[crarko adds: I don't use Dynamic DNS, so I haven't tried this. But stepping through the code makes it look safe to try if you do.]
    •    
  • Currently 3.14 / 5
  You rated: 5 / 5 (7 votes cast)
 
[21,337 views]  

Maintaining a Dynamic DNS automatically. | 14 comments | Create New Account
Click here to return to the 'Maintaining a Dynamic DNS automatically.' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Maintaining a Dynamic DNS automatically.
Authored by: Spliff on Aug 29, '11 10:13:00AM

This looks like a neat and useful tip, but it's not clear--at least to me--where I enter the username and password for the DNS service I use.

If my username is an e-mail, do I enter it in <key>UserName</key> or <string>nobody</string>? And where do I enter my account password for the DNS service?




[ Reply to This | # ]
Maintaining a Dynamic DNS automatically.
Authored by: axcess99 on Aug 29, '11 01:35:19PM

I've been using a launchd file to do this for years. So to answer your question.
Neither, that UserName/nobody is for what local account should be used to execute the command.

for example with dyndns.org you would update the script to:
<string>/usr/bin/curl</string>
<string>--silent</string>
<string>--insecure</string>
<string>-u</string>
<string>[username]:[password]</string>
<string>https://members.dyndns.org/nic/update?hostname=[myhost]</string>



[ Reply to This | # ]
Maintaining a Dynamic DNS automatically.
Authored by: houchin on Aug 29, '11 10:27:00AM

I don't have info on the FreeDNS update policies, but before you install this make sure to check the update policy of your provider. For example, DynDNS specifically considers sending the same info over and over when nothing changes a "bad update" and will block your account if you do it too often.



[ Reply to This | # ]
Maintaining a Dynamic DNS automatically.
Authored by: prokey on Aug 29, '11 02:05:58PM
I had some issues getting this to work on Lion. First, the file was not owned by root:wheel by default, and instead was owned by my username. The permission fix tip yielded an error "No such xattr: com.apple.quarantine" Instead, this command worked:

sudo chown root:wheel /Library/LaunchDaemons/dynamic_dns_updater.plist



[ Reply to This | # ]
Maintaining a Dynamic DNS automatically.
Authored by: DocC on Aug 29, '11 07:24:45PM

Apologies, for asking what I suspect are kind of a n00b questions, but:

1) In this part of the script:

<key>StartInterval</key>
<integer>3600</integer>

Is the value 3600 the value that sets the length between refreshing the DNS page, i.e. 1 hour? (So two hours would be 7200, a day would be 86400Ö?)

And

2) Does running this tax your CPU counting all those seconds?

Thanks for your indulgence.



[ Reply to This | # ]
Maintaining a Dynamic DNS automatically.
Authored by: Thomas Riise on Aug 30, '11 12:08:26AM
OR, you could simply put this entry in your crontab, and it will update every 4th hour:
0 */4 * * * /usr/bin/curl --silent 'https://freedns.afraid.org/dynamic/update.php?YKIJUSiikf83kfj8dhfhuee9jdjd9ejfj99fj9jslRRRT' > /dev/null 2>&1
:-)
---
An Apple a day keeps Microsoft away...


[ Reply to This | # ]
Maintaining a Dynamic DNS automatically.
Authored by: Spliff on Aug 30, '11 11:01:43AM

With this, I get "invalid update url." And where do you enter your FreeDNS login and password with this crontab entry?



[ Reply to This | # ]
Maintaining a Dynamic DNS automatically.
Authored by: dfbills on Aug 30, '11 07:39:50PM

Too bad cron has been depreciated in Lion.

---
-d



[ Reply to This | # ]
Maintaining a Dynamic DNS automatically.
Authored by: usovalx on Aug 31, '11 04:38:05PM

$ ls -l /System/Library/LaunchDaemons/*cron*
-rw-r--r-- 1 root wheel 574 20 Jul 21:57 com.vix.cron.plist

Just like on Snow Leopard.



[ Reply to This | # ]
Maintaining a Dynamic DNS automatically.
Authored by: dfbills on Aug 31, '11 04:51:23PM

I hadn't tried re-enabling. But, I assumed it was fairly simple.

---
-d



[ Reply to This | # ]
Maintaining a Dynamic DNS automatically.
Authored by: poenn on Aug 30, '11 04:04:38AM

Not trying to troll, but itís been years since I last saw a router that did not have support for dynamic DNS built-in. So Iíd first take a look at your routerís config. I would always prefer this. If your router does not support it, then itís a nice hint, of course!



[ Reply to This | # ]
Maintaining a Dynamic DNS automatically.
Authored by: usovalx on Aug 31, '11 04:42:18PM

If you don't care much about it being run as "daemon" (e.g. independend of whether you are currently logged in) it can be easier to just drop it into ~/Library/LaunchAgents.

Just remove
<key>Username</key>
<string>nobody</string>



[ Reply to This | # ]
Maintaining a Dynamic DNS automatically.
Authored by: leamanc on Aug 31, '11 10:06:08PM

True, but I would think in a lot of cases--if someone is truly running a home server--they are not going to be logged into the server box all the time, and will leave it running at the login screen.

I would +1 your comment if I could though, just for providing a clear and concrete difference between LaunchAgents and LaunchDaemons. I know a lot of folks who get confused over which to choose when rolling their own launchd plists.



[ Reply to This | # ]
Maintaining a Dynamic DNS automatically.
Authored by: intrepidsilence on Sep 01, '11 08:00:10AM

While all of this wonderful back-end tweaking is fun I find it a lot easier to use DNS-O-Matic to automatically handle my dynamic DNS updates. It even allows you to update your IP address automatically on opendns.org at the same time as well, so if you are doing any DNS magic with that wonderful service, it will follow you.



[ Reply to This | # ]