Linux IP Updater for Dynamic Networks

Follow

Comments

81 comments

  • Avatar
    barnski2

    I am using a Raspberry Pi to do this, and also to update a No-IP.com dynamic dns, and it works well. However, as a pointer, after spending a while fighting the config, it became apparent that the OpenDNS stanza (as above) seems to need to be first in the config file (i.e. if you have more than one dynamic IP service with ddclient, OpenDNS must be first).

    My working ddclient.conf looks like this:

    <blockquote>

    # Configuration file for ddclient generated by debconf
    #
    # /etc/ddclient.conf

    #
    #opendns
    #
    protocol=dyndns2
    use=web, web=myip.dnsomatic.com
    ssl=yes
    server=updates.opendns.com
    login=opendns_username
    password=‘opendns_password’
    opendns_network_label

    #
    #no-ip
    #
    protocol=dyndns2
    use=web, web=myip.dnsomatic.com
    server=dynupdate.no-ip.com
    login=no-ip_login
    password=‘no-ip_password'

    </blockquote>

    Note that the apostrophes around the passwords are intentional - some documentation indicates that they are required.

    Hope that helps someone - would have saved me an hour or two!

  • Avatar
    barnski2

    no-ip stanza should have a final line which is the no-ip hostname (fqdn)

     

  • Avatar
    Matt Prytuluk

    Thanks for the feedback Barnski2!   Using a raspberry pi for this is pretty sweet nice work!

  • Avatar
    simple2hack

    Thanks for posting!

  • Avatar
    cheznoid

    Thanks for the info - works great on my Raspberry Pi!

    For others that might try this on their Raspberry Pi, you can install it by executing 'sudo apt-get install ddclient' in a terminal window. The configuration file is /etc/ddclient.conf. To check if it's setup properly, look for ddclient output in /var/syslog.

    No need to use the 'chkconfig' or 'service' commands mentioned by mattp above. It is apparently installed as a service, so always runs.

  • Avatar
    przemyslaw

    Linux Mint 17

    1. sudo /usr/sbin/ddclient chkconfig ddclient on
    2. sudo /usr/sbin/ddclient service start

     

     

     

  • Avatar
    techn1976

    thank you przemyslaw

  • Avatar
    techn1976

    lol i am not able to delete my previous comment... So....

     

    this post came first when i googled for help so i am going to add my link here:

    basically i am using debian and i could not get this to work until i found the following link:

     

    https://forums.opendns.com/comments.php?DiscussionID=7723 and just for backup here is the contents:

     

     

    All documented, here you can go: http://www.opendns.com/support/article/101


    My personal recommendation is like that:

    /etc/ddclient.conf:

    daemon=300
    syslog=yes
    mail=root
    mail-failure=root
    pid=/var/run/ddclient.pid
    ssl=yes
    use=web, web=myip.dnsomatic.com
    protocol=dyndns2
    server=updates.opendns.com
    login=your_email_address_registered_with_OpenDNS
    password=your_OpenDNS_password
    Your_OpenDNS_network_label

    /etc/default/ddclient:

    run_ipup="false"
    run_daemon="true"
    daemon_interval="300"

    And no, you don't need a DynDNS account at all for this.

  • Avatar
    markdewey

    Here's a really easy way to update this on Linux.

    * Make sure you have curl installed. Do sudo apt-get curl

    * Use this in your script (where email is your email and password is your password): curl -u email:password https://updates.opendns.com/nic/update

     

    Here's an example Python 3 script that you could autoload with your computer:

     

    #!/usr/bin/env python3
    import shlex, subprocess;
    command=shlex.split("curl -u email:password https://updates.opendns.com/nic/update");
    subprocess.call(command);
    print("");

     

  • Avatar
    markdewey

    I forgot where I found the link that makes this possible (and that you can use Curl to login to it, but I believe it was somewhere on this site.

  • Avatar
    markdewey

    Here's a better example script that keeps trying until the Internet is connected (the Internet connection method comes from Kevin C's answer at stackoverflow at this URL: http://stackoverflow.com/questions/3764291/checking-network-connection )

     

    #!/usr/bin/env python3

    import shlex, subprocess, urllib, urllib.request, time;

    def internet_on(reference):
    try:
    urllib.request.urlopen(reference, timeout=1)
    return True
    except urllib.request.URLError:
    return False

    while internet_on("http://www.opendns.com/")==False: #Keep trying until a connection with the Internet is connected.
    time.sleep(9);

    #Update opendns IP address
    command=shlex.split("curl -u email:password https://updates.opendns.com/nic/update");
    subprocess.call(command);
    print("");

  • Avatar
    markdewey

    Sorry, you'll have to figure out where the indents are yourself, I guess (but it's pretty obvious if you know Python).

  • Avatar
    markdewey

    Nevermind, I'll tell you. Indent everything from try to return false, once. Add an extra indent from urllib.request... to return False. Indent time.sleep(9).

  • Avatar
    markdewey

    Erg. Nevermind the extra indent I mentioned that was wrong. Indent from urllib.request... to return True the extra time, and then indent return False an extra time.

  • Avatar
    markdewey

    Okay, I'll make it extra-easy on you and just attach the file. Be sure to change the email and password to yours. Too bad I didn't think of that earlier. Have it start up with your computer. 

     

    I don't think I can delete previous comments.




    update_opendns.py
  • Avatar
    markdewey

    Here's a better version I just made. This keeps checking periodically for a broken connection and restarts the script if it finds one. This is because sometimes people unplug the router and plug it back in, but they don't restart their computers (and that could circumvent opendns). So, restarting the script when the connection is lost solves the problem, because when they connect again, it'll be updated again.




    update_opendns.py
  • Avatar
    markdewey

    You can erase that os, sys part of the import, if you want, but it won't hurt to leave it in. I forgot they were there.

  • Avatar
    markdewey

    Oh, in that last shlex.split("update_dns") part "update_dns" is the path to your/this script. So, you can copy the script to somewhere like /opt/bin/ (a root location) and then replace "update_dns" with "/opt/bin/update_opendns.py" (make sure the script is executable).

  • Avatar
    contact

    Hi guys, does anyone know hhat data do i need to add on a fortigate 60B unit for the update to work?




    ddns_fgt_conf.JPG
  • Avatar
    Alexander Harrison

    It doesn't look like that router has the fields required to update OpenDNS. This thread is regarding the Linux updater, and if you have questions about another produce I'd suggest creating a new thread. 

  • Avatar
    maplesyrup

    Dear all,

    I'm using Mint 17.

    I do "To turn on the Updater, use: sudo /sbin/chkconfig ddclient on " but I get

    sudo: /sbin/chkconfig: command not found

     

  • Avatar
    nubrigol

    Please add this to the article!

    1. You're login is your email address with OpenDNS.

    2. If you have spaces in your network label, replace them with underscore ( _ ).

    3. If you have special characters in your password (and you should!) wrap the password in single-quotes ( ' ). (And if there are any single-quotes in your password, put backslash ( \ ) before them).

     I had to figure all this out on my own!

     

  • Avatar
    Matt Prytuluk

    Thanks for the feedback nubrigol, I've updated the article accordingly!  Much appreciated. 

  • Avatar
    stefano.finalnofap

    The chkconfig file no longer exists. Please update the guide, because right now I'm not able to complete this walkthrough. Is there any other command that can replace chkconfig, and, if there is, how can I use it?

    Thanks

  • Avatar
    rotblitz

    Depending on your Linux disto, update-rc.d, sysv-rc-conf, systemd and/or systemctl seem to be the replacements.  You use these as documented for your distro.

  • Avatar
    citygatedc

    New to linux, educational non profit trying to keep costs down using linux.  can anyone provide instructions on how we would set this up so the updater wouldn't need to be run manually, but automatically when the computer is started?

  • Avatar
    rotblitz

    This is the same as you start any other service automatically with your specific Linux distro. You obtain the instructions from your manuals or from the forum community of your distro.  In case of ddclient you can also refer to their specific documentation.

  • Avatar
    mark_wish

    markdewey, can you please check your script and make sure your real user / pass are not in there?

    Also, instead of having it stay alive wouldn't it be better to set a cron job to run every 30/60/whatever minutes and compare a previously saved IP?  That way no need to install this into /etc/init.d and for other reasons.  I do something like this using my webhost and use bot.whatismyipaddress.com, compare against the previously saved IP, and push to a remote file via keyed SCP.  So something similar here perhaps where it runs / pushes only when necessary?

  • Avatar
    sanric

    Thanks for the note on the username and password in the file. The password for that account has been changed.

    Anyway, I'm not familiar with cron jobs, yet, although I have read the term in passing, I think. So, you'll have to be the judge of that. Whatever the case, this method works better than anything else I've tried (but I haven't tried a cron job, whatever that is). Feel free to make a tutorial (but don't feel obligated for my sake; but if for anyone, for people generally who want to know).

  • Avatar
    markdewey

    Just in case you're thinking I have two accounts. I set that other one up for a friend. Thankfully, there was no personally identifiable information in the account, or anything like that.

Please sign in to leave a comment.