Updating DDNS on EdgeRouter Lite Using Crontab

Backstory

Earlier this summer when I was working more on the new church networking equipment, I decided that they needed a hostname for external access. Since their website is hosted somewhere else, there’d been no need for a real domain name to point at the router.

Currently, I am using No-IP’s free Dynamic DNS (DDNS). The inconvenience of No-IP is that they require you to update or refresh your hostname every month to keep them from expiring. There are a number of different ways to do that, but in this case, I wanted my EdgeRouter Lite to update No-IP with my current external IP address.

Configuring ERLite for No-IP

As of firmware 1.8.5, the ERLite natively supports No-IP, and I configured it from the command line as follows:

configure
set service dns dynamic interface eth0 service noip host-name **myhostnane.com**
set service dns dynamic interface eth0 service noip login **mynoipemail**
set service dns dynamic interface eth0 service noip password **mynoippassword**
set service dns dynamic interface eth0 service noip protocol noip
commit
save
exit

See this page for more details. (Note that the page is old, and doesn’t show noip as a protocol, but per this forum post, it’s available in firmware 1.8.5 and later)

The Problem

To my surprise, however, the ERLite does not send an update to the DDNS provider unless the external IP address changes. (See the last paragraph of this page) While we don’t have a static IP address from our ISP, it doesn’t tend to change. So this was becoming a problem.

Ever since I set this up, I’ve been getting emails every month saying “Your hostname is expiring, click here to renew”. The would always catch me at a busy moment, but I’d click the button and promptly forget about it.

Today was the day that I was finally going to solve this issue.

A Solution

I knew that the No-IP configuration in the ERLite was correct, because if I clicked the Force Update button from the web interface, or issued update dns dynamic interface eth0 from the CLI, No-IP would show it as being refreshed. (If you go to No-IP’s website, you can see the last time that your hostname was refreshed.)

Now I just needed to find a way to script this.

Being a small Linux box, the ERLite has cron functionality. If I could just add the above command to root’s crontab, this would be an easy fix. I tried that, but it didn’t work. At the time I didn’t realize that the update command was actually alias update='_vyatta_op_run update. After some more digging, I found that this pointed to this Perl script:

sudo /opt/vyatta/bin/sudo-users/vyatta-op-dynamic-dns.pl --update-ddns --interface "$IFNAME"

My first reaction was to add this to root’s crontab, and it worked! But I wasn’t satisfied. I am usually a little leery of bypassing wrappers that are written by the devs.

The Better Solution

I then stumbled on this page on How to Run Operational Mode Command From Scripts. This was exactly what I was looking for. The vyatta-op-cmd-wrapper is what I needed to be able to properly call the update dns dynamic interface eth0.

Here is the script I now have called from root’s crontab.

Note that this is also why my original attempts at just adding update dns dynamic interface eth0 to root’s crontab failed.

Bonus Tidbits

Here are a couple commands I found useful for troubleshooting.

$ show dns dynamic status
  interface : eth0
  ip address : XXX.XXX.XXX.XXX
  host-name : myhostname.ddns.net
  last update : Sat Nov 5 15:13:05 2016
  update-status: good

This one shows the ERLite’s configuration for the DDNS provider.

$ configure
# show service dns dynamic
  interface eth0 {
      service noip {
          host-name **myhostnane.com**
          login **mynoipemail**
          password **mynoippassword**
          protocol noip
      }
  }
This entry was posted in WPPC Networking Project and tagged , . Bookmark the permalink.

3 Responses to Updating DDNS on EdgeRouter Lite Using Crontab

  1. T. A. says:

    Thank you so much for the information. It solved my problem. The manually edited crontab will be lost in firmware update, though. I think it is better to use the provided task-scheduler feature to run the script (here at 4:23 every morning):

    $ configure
    # show system task-scheduler
    task ddns_update {
    crontab-spec “23 4 * * *”
    executable {
    arguments “update dns dynamic interface eth0”
    path /opt/vyatta/bin/vyatta-op-cmd-wrapper
    }
    }

  2. Hans Guthrie says:

    Hi T. A.,

    Thanks for the comment. I actually did end up using the task-scheduler feature…but I never got around to publishing the update blog post. I should do that…

  3. Pingback: Part 2: Updating DDNS on EdgeRouter Lite Using Crontab | Sysadmin Ramblings

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.