NSLU2-Linux
view · edit · print · history

Introduction

This HowTo is intended to provide information on updating a No-IP user account from an NSLU2. No-IP provides DNS (domain name service) for sites with dynamic IP addresses. For more information: http://www.no-ip.com

To actively have your NSLU2 update your IP address with the No-IP service a client is needed. There is a client available using ipkg that appears to be the standard No-IP Linux client ported to the NSLU. This client appears to work well enough, but it runs in a daemon mode. This solution involves a shell script that checks for an updated IP address, updates if it has changed, and then exits. It can be scheduled using cron and will not consume CPU or memory when inactive.

Requirements

I have this working on my NSLU2, but am I still trying to factor this out to the minimum requirements. My setup:

  • NSLU2
  • V2.3R29-uNSLUng-5.5-beta
  • ipkg - wget
  • Ability to telnet or ssh into the NSLU2
  • No-IP.com account (free)

Installation

Install wget
# ipkg install wget

Create noipupdate script
/opt/bin/noipupdate:

#!/bin/sh
# noipupdate - Update IP address for www.no-ip.com account.

# 2006/03/01 v0.01 kilgore@pillarcom.com - Initial script
# 2006/03/02 v0.02 kilgore@pillarcom.com - Updated based upon http://www.no-ip.com/integrate/
#       Partial support for No-IP Dynamic DNS Update Request Specification v2.1 (Standard)
# 2006/03/12 v0.03 johannes.keukelaar@gmail.com - Require user intervention after an error.
# 2007/11/10 v0.04 jlpamart@yahoo.fr - errors corrections (return --> exit and "")
VERSION=v0.04

# Change the following to your NO-IP username (email address), password,
# and NO-IP hostname. Only supports a single hostname. No support for
# multiple hostnames or groups

USER=user@emaildomain.com
PASS=password
HOST=host.noipdomain.tld

# Define the user agent string
USERAGENT="noipupdate $VERSION NSLU2 Client (http://www.nslu2-linux.org/wiki/HowTo/NoIPUpdate)"

# Define some filenames
PREVIPFILE=/var/tmp/noipupdate.dat
LOCKFILE=/var/tmp/noipupdate.lock

# Output timestamp
echo -n `date "+%Y/%m/%d %H:%M:%S"`" noipupdate "

# Determine if there was an error during a previous invocation.
if [ -f $LOCKFILE ]; then
  echo "Not running due to previous error ($LOCKFILE: `cat $LOCKFILE`)."
  exit 255
fi

# Get the current IP address from no-ip perspective
CURIP=`wget -U "$USERAGENT" -q http://ip1.dynupdate.no-ip.com/ -O -`

# Verify that the result
PAT='.*[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*'
if ! (echo $CURIP | grep -q '^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*$'); then
        echo "$0: Invalid IP address";
        exit 1
fi

# Retrieve the previous IP address
if [ -f $PREVIPFILE ];then
        OLDIP=`cat $PREVIPFILE`
else
        OLDIP=UNKNOWN
fi

# Compare the current with the old and see if there is a change
if [ "$CURIP" = "$OLDIP" ]; then
        echo "No IP address change ($OLDIP)"
        exit 0
fi

# Attempt to update IP address
RESULT=`wget -U "$USERAGENT" -q "http://dynupdate.no-ip.com/dns?username=\
$USER&password=$PASS&hostname=$HOST&ip=$CURIP" -O - | sed -e s/.*://`
if [ "$RESULT" = "0" ] || [ "$RESULT" = "1" ]; then
        echo "Update successful ($CURIP)"
        echo $CURIP > $PREVIPFILE
        exit 0
elif [ "$RESULT" = "2" ]; then
        echo "Bad host";
        echo "Bad host" >$LOCKFILE
        exit 2
elif [ "$RESULT" = "3" ]; then
        echo "Bad password";
        echo "Bad password" >$LOCKFILE
        exit 3
elif [ "$RESULT" = "4" ]; then
        echo "Bad username";
        echo "Bad username" >$LOCKFILE
        exit 4
else
        echo "$0: Unexpected error ($RESULT)"
        echo "Unexpected error ($RESULT)" >$LOCKFILE
        exit 255
fi

The file can also be downloaded

Note that in some environments wget does not recognize the -U parameter (user agent). In this case, simply substitute -U by --header or remove the complete parameter with its value.

For those who intend to edit the script file in Windows: be sure you save it in UNIX format with only LF instead of CR+LF.

Make noipupdate executable
# chmod 755 /opt/bin/noipupdate

Configuration

Edit /opt/bin/noipupdate:

USER=user@emaildomain.com
PASS=password
HOST=host.noipdomain.tld

Modify the USER, PASS, and HOST values to your appropriate No-IP account settings

Testing

If the script has been installed and configuration has been completed then run noipupdate:
# /opt/bin/noipupdate
If everything was successful then you should see:
2006/03/02 22:59:57 noipupdate Update successful (64.233.187.99)
Otherwise you should see an error message such as:
2006/03/02 22:59:57 noipupdate Bad password (64.233.187.99)
Hopefully the reason for the error will be obvious. You should fix the issue and then force an update (see the next section).
Any invocation of the script after an error has occurred will refuse to update without user intervention, as per the No-IP specifications:
2006/03/12 23:13:33 noipupdate Not running due to previous error (/var/tmp/noipupdate.lock: Bad password).
Fix the problem (in this case, by correcting the password in the script), then remove the /var/tmp/noipupdate.lock file.

Forcing an update

If for some reason noipupdate gets out of sync with the No-IP service or for some other reason you would like to force an update to the No-IP servers, then you should remove the /var/tmp/noipupdate.dat file that stores the last used IP address.
# rm /var/tmp/noipupdate.dat
# /opt/bin/noipupdate

Recovering from an error

If noipupdate complains about 'Not running due to previous error', you should look at the contents of the file /var/tmp/noipupdate.lock, which is also printed in the message. With the printout and possibly the description of error codes at http://www.no-ip.com/integrate/response/, determine what the problem is. Fix the problem, then remove the /var/tmp/noipupdate.lock file (and probably also the /var/tmp/noipupdate.dat file, to force an update), and rerun noipupdate:
# rm /var/tmp/noipupdate.lock /var/tmp/noipupdate.dat
# /opt/bin/noipupdate

Process

Each time that noipupdate runs it checks the current external IP address and compares it to the IP address from the previous time noipupdate was run. If it is the same then noipupdate exits and takes no further action. If the IP addresses are different then noipupdate will attempt to update the No-IP service with the current IP address.

Scheduling

For most people the entire point of this exercise is to automate the updating of the No-IP information. So now that we have a working No-IP client we need a way to automatically run it.

Add the following to /etc/crontab:

*/15 * * * * root /opt/bin/noipupdate >> /var/log/noipupdate.log 2>&1

This will cause the noipupdate client to run every 15 minutes and log its results in /var/log/noipupdate.log

Limitations

This script has been minimally tested and has been presented here on 2006/3/2 for testing and use by anyone who may be interested.

There is not support for updating multiple No-IP hosts or groups. This should be relatively simple to implement, but is probably not needed for the majority of users. If there is sufficient interest support for these functions can be added.

References

http://www.no-ip.com/integrate/
http://www.no-ip.com/downloads.php?page=linux
http://www.nslu2-linux.org/wiki/HowTo/DynDNSupdate

Revision

2006/3/2 - Initial page and script added to wiki - Slackmaster (kilgore$pillarcom.com)
2006/3/12 - Updated with support for not running after an error - johannes.keukelaar@gmail.com


ipkg install noip should just give you the official client as optware package, /opt/bin/noip2 -h for usage.

view · edit · print · history · Last edited by BrianZhou.
Based on work by jean-luc pamart, arnebaierwebde, Johannes, and slackmaster.
Originally by slackmaster.
Page last modified on November 11, 2007, at 05:00 PM