newspaint

Documenting Problems That Were Difficult To Find The Answer To

How To Use dnsdynamic.com With OpenWRT

Update (2014-09-03): Barrier Breaker has LuCI module support for dynamic DNS. See this blog article for details.


So you have your custom router with OpenWRT on it and you have a dynamic hostname with dnsdynamic.com or dnsdynamic.org. How do you get your OpenWRT router to send IP updates whenever you connect on the WAN interface?

In my case the WAN interface uses the pppoe-wan device. You might be using eth1 or similar – so make the appropriate changes in the following scripts for your situation.

I do it this way; create a script in /root/dnsdynamic.sh:

#!/bin/sh

WANIF="pppoe-wan"
MYHOST="newspaint.dnsdynamic.com"
USERNAME="admin@newspaint.wordpress.com"
PASSWORD="secret!Password"

MYIP=`ifconfig ${WANIF} |grep -o -E 'inet addr:([0-9.]+)' |grep -o -E '([0-9.]+)'`
URL="https://www.dnsdynamic.org/api/?hostname=${MYHOST}&myip=${MYIP}"
/usr/bin/wget -O - --no-check-certificate --http-user "${USERNAME}" --http-password "${PASSWORD}" "$URL"

Don’t forget to make the script executable:

chmod 755 /root/dnsdynamic.sh

Next, get the package “wget” for your OpenWRT router (the default doesn’t have functions for password-protected web pages, so I go to the web interface on my router, select System -> Software, [update packages if I haven’t for a while], Filter: type wget, click “Find package”, then below on the “Available packages” tab select the wget package to install).

Finally you can test the script by running it on the command line (on your router as you’ve SSH’d in as root). You should see output similar to the following:

root@myOpenWRTRouter:~# /root/dnsdynamic.sh
--2013-11-10 17:12:09--  https://www.dnsdynamic.org/api/?hostname=newspaint.dnsdynamic.com&myip=41.42.43.44
Resolving www.dnsdynamic.org... 84.45.76.100
Connecting to www.dnsdynamic.org|84.45.76.100|:443... connected.
WARNING: cannot verify www.dnsdynamic.org's certificate, issued by `/C=US/O=GeoTrust, Inc./CN=RapidSSL CA':
  Unable to locally verify the issuer's authority.
HTTP request sent, awaiting response... 401 Authorization Required
Connecting to www.dnsdynamic.org|84.45.76.100|:443... connected.
WARNING: cannot verify www.dnsdynamic.org's certificate, issued by `/C=US/O=GeoTrust, Inc./CN=RapidSSL CA':
  Unable to locally verify the issuer's authority.
HTTP request sent, awaiting response... 200 OK
Length: 6 [text/html]
Saving to: `STDOUT'

 0% [                                       ] 0           --.-K/s              nochg
100%[======================================>] 6           --.-K/s   in 0s

2013-11-10 17:12:10 (12.6 KB/s) - written to stdout [6/6]

Typical responses from dnsdynamic are nochg and good <ip_address>.

Finally – how to make it update every time you connect to the WAN?

Create a script in /etc/hotplug.d/iface named 30-dnsdynamic:

#!/bin/sh
# This script is executed as part of the hotplug event with
# HOTPLUG_TYPE=iface, triggered by various scripts when an interface
# is configured (ACTION=ifup) or deconfigured (ACTION=ifdown).  The
# interface is available as INTERFACE, the real device as DEVICE.

[ "$DEVICE" != "pppoe-wan" ] && exit 0

. /lib/functions.sh
. /lib/firewall/core.sh

fw_init
fw_is_loaded || exit 0

case "$ACTION" in
        ifup)
                /root/dnsdynamic.sh >/tmp/dnsdynamic.log 2>&1
        ;;
esac

This script triggers whenever an interface is brought up or down – but will exit if the device is not pppoe-wan and will only take action if the interface is being brought up (as this is when your interface will be assigned a dynamic IP address and so should make the IP address notification).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: