Dynamic DNS – open up your Pi’s webserver to the World

I’ve installed Raspcontrol by Jacob Clark along with Apache and PHP. I did a guide for that in a previous post.

What I want to do now is to get the webserver running it open to the World.
I’m on a dynamic IP with my ISP (I think!) so I want a way of getting the Pi to use some kind Dynamic DNS  so I can refer to it by hostname.

I looked around for Dynamic DNS providers and found DNSDynamic.org
Looking at http://www.dnsdynamic.org/api.php, I can see they have an API that can be configured with ddclient, whatever that is. It’s got an obscure name, so it’s probably linux!

So first of all:

  • Go to www.dnsdynamic.org and register.
  • Then, once you’ve validated using their registration email, add a new domain.
  • For the purposes of this tutorial, let’s go with
    wibble.dnsdynamic.com

Then:

  • Start the Pi, login as root and then:
  • apt-get install ddclient

That installs and I automatically get an interface pop up on my screen:

So I choose other…

  • Asking me for the name of the provider server, so let’s put in www.dnsdynamic.org
  • DNS Dynamic uses the dyndns2 protocol, so choose that.
  • Enter your username and password.
  • It now asks for the network interface to use. Now, I use Wifi, so I put in wlan0, but if you are using a cabled LAN connection, you’ll use eth0.
  • Now enter your domain – wibble.dnsdynamic.com
  • At this point, ddclient will configure itself. At this point, I rather hope that it tells me what it does next!
  • Okay, so it installs more stuff…
  • Interesting… the installation completes and… tells me nothing…
  • Right, looking at the ddclient documentation it tells me where the configuration file is. Not quite right in the documentation – the config file is at /etc/ddclient.conf
  • Apparently, the way to run it automatically is to add the following to your /etc/rc.local:
    /usr/sbin/ddclient -daemon 300 -syslog
  • The ‘300’ is the number of seconds it should wait before checking to see if the IP address has changed. I think this is fine, even for my wifi connection with it’s customary 2 minute connection delay.
  • So, let’s try it!
You check your IP address by going to dnsdynamic.com, logging in, going to “manage” and editing your existing domains.
If you are behind a router (and let’s face it, who isn’t!?) then this will (incorrectly) show your INTERNAL IP address. (Mine says 192.168.1.80 for instance). We don’t want that, so I found a help page: http://superuser.com/questions/389125/ddclient-updating-to-local-ip-instead-of-public-ip
To fix:
  • Edit /etc/ddclient.conf (for example > nano /etc/ddclient.conf)
  • Change the line
    use=if, if=wlan0
    and add a # in front of it.
  • Add the line
    use=web, web=checkip.dyndns.org
  • Save and quit.

You  need to kill the current ddclient and restart it:

  • ps -ef | grep ddclient
  • Make a note of the process id (which is the first number on the left)
  • kill -9 <process id>
  • Then re-run ddclient by typing:
  • ddclient

This will run it in the background and update the dynamicdns.org IP address to your external ip.

Go back to dnsdynamic.org and check your existing domains again. You should have your external IP address showing now. (I did).
You should now be able to: ping wibble.dnsdynamic.org and get that same IP address back.
The next thing to do is to do a port forward on your router. There are various guides to do this. You will need to point port 80 (HTTP) of your router at your INTERNAL IP address, port 80, or however your router identifies the destination. (Assuming that’s the port your webserver is running on).
I managed to do this on my BT Home Hub without much trouble
Now, to test it. First of all you cannot just put your dynamic DNS hostname into your browser and expect it to work. I think it’s got something to do with looping back to yourself.
So, go to www.proxify.com and type your wibble.dnsdynamic.com into there. You should get your Pi’s homepage! Wahey!

17 comments for “Dynamic DNS – open up your Pi’s webserver to the World

  1. Ross Hetherington
    3 August 2012 at 9:57 pm

    >Note there is a known problem with ddclient 3.8.0-11.3 on debian that means the ip address in the ddclient cache isn't updated on some providers. See:
    http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=528950
    Message #39

    I managed to apply the patch from here manually to my raspberry pi /usr/sbin/ddclient file and it now correctly updates the ip= part of the cache file.

    Patch is described here:
    http://sourceforge.net/apps/trac/ddclient/changeset/120

    • daris tan
      30 August 2013 at 10:14 am

      Can you give me more steps how to patch it, I only see alot of text but where to put it or enter them?

  2. Unknown
    8 August 2012 at 12:35 pm

    >Hi,

    A startup script is automatically installed in /etc/init.d/ddclient, when you install the package (and it appears to be set to run automatically).

    If you want to run it without having to do a reboot do:
    sudo /etc/init.d/ddclient start

  3. 20 October 2012 at 1:09 am

    I’ve read several excellent stuff here. Definitely worth bookmarking for revisiting. I surprise how much effort you put to create this type of great informative web site.

  4. Quintinjvr
    30 January 2013 at 10:39 pm

    Hello, I need some help please, almost feel like smashing my keyboard! LOL.

    No matter what I do, when i type:
    /etc/ddclient.conf
    as the root user and even with sudo as a prefix, it keeps on telling me, Permission denied 🙁

    Can anyone please help? I removed the ddclient and reinstalled it, and get the same each and every time.

    it returns with bash: /etc/ddclient.conf: Permission denied

    Thanx

    • 31 January 2013 at 6:58 am

      Oh, I know what the problem is. My instructions aren’t clear. What you need to do is to EDIT that file. For example:
      nano /etc/ddclient.conf

      The permission denied error is because you’re trying to run it like a program. I’ve amended the instructions to be clearer. Sorry about that!

  5. Quintinjvr
    31 January 2013 at 7:48 am

    Awesome! Thank you so much. I am a bit of a Linux newby, so please excuse. :-p
    All is working now and is making sense 😉

    Great tutorial!

    Keep well

    • 31 January 2013 at 8:24 am

      You’re very welcome – thanks for visiting the blog 🙂 (I’m fairly new to Linux too – steep learning curve isn’t it!)

  6. daris tan
    30 August 2013 at 9:57 am

    ps -ef | grep ddclient
    Make a note of the process id (which is the first number on the left)
    kill -9
    Then re-run ddclient by typing:
    ddclient

    I am struck at above command , does not seem to work, so I reboot my pi but still doesn’t work.

  7. Tom
    19 November 2013 at 9:16 am

    #!/bin/bash
    #
    # This script was made by tom.bergfors@gmail.com.
    # You are allowed to do whatever you want with it.
    #
    # Need to have curl installed: sudo apt-get install curl (or try without sudo in the beginning)
    #
    # User should edit the following three variables:

    USER=”my.email@hotmail.com”
    PASSWD=”Mysecret”
    DOMAINNAME=”rasperry.flashserv.net”

    ##################################################
    # Script begins here, do not edit anything below #
    ##################################################

    echo “#######################################################################################################”
    date
    echo ” ”
    MYIP=`curl -s -S http://myip.dnsdynamic.org`
    # as an alternative, it is also possible to use icanhazip.com
    # MYIP=`curl -s -S http://icanhazip.com`

    DNSIP=`nslookup ${DOMAINNAME} | awk ‘/Name/{getline; print substr($02, index($0,$1))}’`

    if [ “$MYIP” != “$DNSIP” ]

    then

    echo “Need to update DNS domain ${HOSTNAME} from IP adress ${DNSIP} to my IP address ${MYIP}”

    echo “On a succesful update, the next line should say “good ${MYIP}””

    curl -s -S –user ${USER}:${PASSWD} https://www.dnsdynamic.org/api/?hostname=${DOMAINNAME}&myip=${MYIP}

    else
    echo DNS domain ${DOMAINNAME}
    echo have ip address: ${DNSIP}
    echo ” ”
    echo My ip address is ${MYIP}
    echo ” ”
    echo No DNS update necessary.
    fi

    • Frange
      31 January 2016 at 3:24 pm

      Well done. I was thinking about a similar way to update the ip address with the dnsdynamic API:

      “A simple example to update a domain using the API directly;

      https://username:password@www.dnsdynamic.org/api/?hostname=techno.ns360.info&myip=127.0.0.1

      Thanks for the code !!

      • Frange
        31 January 2016 at 4:53 pm

        I made a few changes because i was having problems to update with your “curl line”

        curl -s -S -X GET “https://www.dnsdynamic.org/api/?hostname=”${DOMAINNAME}”&myip=”${MYIP} -u ${USER}:${PASSWD}

  8. Tushar
    2 January 2015 at 6:14 am

    Thanks for the great tutorials. But your link for Jacob Clark is not working. I was curious to see what is that.

    Also is there any option to subscribe to your new posts by email?

    • recantha
      2 January 2015 at 8:15 am

      Hi.
      I’ve added a widget to the sidebar that will allow you to subscribe to new posts. Please try it out and let me know if it doesn’t work 🙂

      Mike

  9. 20 March 2016 at 7:19 pm

    Hi Mike,
    I’ve installed Raspcontrol on all of my Raspberries, however I can’t get it to work with Jessie. Works like a charm unter Wheezie.
    did YOU install it under Jessie and, if yes, what did you do to make it work?

    • Michael Horne
      20 March 2016 at 9:22 pm

      Hi. Nope, I’m afraid this was back in the early days (July 2012). Not tried it with Jessie

  10. Zak Zebrowski
    15 April 2016 at 5:17 pm

    FYI, ngrok.com (and other services) allow tunneling without modifying firewalls.

Leave a Reply

Your email address will not be published. Required fields are marked *