Tutorials Linux DDNS Update Client wget

From WebOS Internals
Revision as of 05:24, 10 September 2009 by Bkw (talk | contribs)
Jump to navigation Jump to search

This document contains instructions for setting up your Pre to automatically update a dynamic DNS hostname to your Palm Pre's IP address (assigned by your data service provider).

If you're using the Optware Package Feed you might want to check out ez-ipupdate or INADYN. However, if your dynamic DNS service isn't supported by either of these, you're building a custom service, or you want a freedns.afraid.org solution that doesn't require an always-on daemon, this guide may be for you.

This mechanism functions by adding a priority default routing rule that forces all traffic to go over the ppp0 (EV-DO) connection. This ensures we're updating your service with your ppp0 ip and not your eth0 (Wifi) ip. It optionally then finds your IP address from http://checkip.dyndns.org. Then, it calls your update URL. Finally, it removes the default route it created in step 1.

Prerequisites

  • This page assumes that you have just finished the procedure on the Portal:Accessing_Linux page, and are still logged in as root via telnet, novaterm, or novaproxy.
  • This page assumes you have a Dynamic DNS service account with a service that provides URL based updating (i.e. http://freedns.afraid.org)

Enabling write access to the file system

 mount -o remount,rw /

Obtain the Update URL provided by your service

For http://freedns.afraid.org, log in, and find the 'Direct Update URL' for your dynamic DNS entry. Mine looks like this:

 http://freedns.afraid.org/dynamic/update.php?ZzYyXxWwUuTtSsRr==

This updates the IP of my DNS entry to the IP of the client. We need to make sure we call this address from the ppp0 interface so that it updates to the correct IP. When the Pre is connected to a wifi connection, a default routing entry forces all data to go over that connection.

However, your service may differ, and require different information (example):

 http://mydynamicdnsservice.com/?host=myhost.com&Ip=99.123.222.101


This example doesn't require the caller to be from the new target IP address, and won't need the routing entries.

Update your service whenever your ppp0 (EV-DO) IP address changes

You can do this by adding a script to /etc/ppp/ip-up.d called 09update-ddns.

This is the script for the first example:
Use this one if you don't get to or don't want to submit an IP arbitrarily, and your dynamic dns service just uses whatever IP the http request came from.

#!/bin/sh
# pppd provides IFNAME and IPREMOTE for us
ip route add default via $IPREMOTE dev $IFNAME metric 1
wget -qO- http://freedns.afraid.org/dynamic/update.php?ZzYyXxWwUuTtSsRr==
ip route del default via $IPREMOTE dev $IFNAME metric 1
 

This is the script for the second example:
Use this one if you need to or want to supply the IP yourself to the dynamic dns service.

#!/bin/sh
# pppd provides IPLOCAL for us
wget -qO- http://mydynamicdnsservice.com/?host=myhost.com&Ip=$IPLOCAL
 

Make this script executable

chmod 755 /etc/ppp/ip-up.d/09update-ddns
 

Also note that curl is also installed. Wget is a faster and lighter and works in most cases, but curl can do more and harder things than wget so it's something to remember if you want to hit some web pages that weren't necessarily designed to be accessed non-interactively.

Remount the file system as readonly

mount -o remount,ro /

It didn't work. What else can I try?

Try adding some debugging to the script. It wasn't working for me so I did this, capture the environment set up by pppd and the output of wget to a file.

#!/bin/sh
L=/media/internal/ppp_env.txt
set >$L
wget -O - "http://svc.joker.com/nic/update?username=MYDDNSUSERNAME&password=MYDDNSPASSWORD&hostname=pre.mydomain.net&myip=${IPLOCAL}" >>$L 2>&1
 

Then after down/up the evdo connection, get back in and look at that ppp_env.txt file, and it showed me that wget couldn't resolve my dyndns service providers web site:

less /media/internal/ppp_env.txt
[...]
wget: bad address 'svc.joker.com'
 

Most likely it's just being called too soon after the connection is formed, and it just needs to retry a few times, with a delay between retries. Real wget has such retry & wait options, but the stock wget on the Pre is just the busybox built-in and it doesn't have any of those options.

You could write a retry loop in the shell script to re-run the same wget command a few times, but, the Pre does also ship with a full-featured standalone version of curl which you could use instead of wget, and take advantage of curls retry options:

#wget -O - "http://svc.joker.com/nic/update?username=MYDDNSUSERNAME&password=MYDDNSPASSWORD&hostname=pre.mydomain.net&myip=${IPLOCAL}" >>$L 2>&1
curl --retry 6 http://svc.joker.com/nic/update?username=MYDDNSUSERNAME&password=MYDDNSPASSWORD&hostname=pre.mydomain.net&myip=${IPLOCAL}" >>$L 2>&1
 

And voila. That fixed it for me. So now just remove the debugging: (Commented out the L=..., set >..., and the >>$L ... at the end of the curl command and added "-s" to the curl options)

#!/bin/sh
#L=/media/internal/ppp_env.txt
#set >$L
curl -s --retry 6 "http://svc.joker.com/nic/update?username=MYDDNSUSERNAME&password=MYDDNSPASSWORD&hostname=pre.mydomain.net&myip=${IPLOCAL}" # >>$L 2>&1
 

attributions

  • raeb
  • dreadchicken
  • Bkw 04:24, 10 September 2009 (UTC)