Difference between revisions of "Tutorials Linux DDNS Update Client wget"

From WebOS Internals
Jump to navigation Jump to search
(make script code more cut/paste friendly and prevent trying to make sample urls clickable)
(add note about missing wget / misleading wget in title)
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
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).
+
==Preamble==
 +
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), using only software that comes installed stock on the Pre (other than the small shell script you will write) and not requiring a daemon process running all the time to monitor the connection (other than pppd itself, which is what makes the connection in the first place, not anything extra).
  
If you're using the Optware Package Feed you might want to check out [[Tutorials_Linux_DDNS_Update_Client_ez-ipupdate|ez-ipupdate]] or [[Tutorials_Linux_DDNS_Update_Client_INADYN|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.
+
If you're using the Optware Package Feed you might want to check out [[Tutorials_Linux_DDNS_Update_Client_ez-ipupdate|ez-ipupdate]] or [[Tutorials_Linux_DDNS_Update_Client_INADYN|INADYN]]. However, if your dynamic DNS service isn't supported by either of these, you're building a custom service, or you want a solution that doesn't require an always-on daemon or installing any additional software, 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.
+
There are many ddns service providers and most of them offer some way to update your ddns entry via URL.
 +
There are two main ways that a ddns service provider obtains your dynamic IP from you. Some providers use one way, some use the other way, some provide both methods and allow you to use whichever way is more convenient for you.
  
==Prerequisites==
+
* In one way, call it Type A, You submit an http request to a cgi on their server, and their server uses the IP that the request came from.
* 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)
+
One potential advantage to this method (for other environments besides the Pre) is that the url is static. It doesn't need any variables, and your script or program doesn't need to figure out what your current IP is when it runs. This can be good for PC's behind NAT routers that don't have a built-in ability to update your particular ddns service.
 +
 
 +
However on the Pre this advantage is outweighed by the need to ensure that this request always goes out via the evdo connection even if you happen to be near a wifi access point which would be used otherwise. This is so that the ddns service always gets your evdo IP, never the IP of any wifi access points you might happen to be near at the time. The evdo connection is the only IP that will be useful for remotely accessing the Pre.
 +
 
 +
To do that, on the Pre, we momentarily make the ppp0 connection the highest priority by adding a routing table entry just before updating the ddns service, and remove it immediately after. This does not affect any of the existing routing table entries of the moment, just temporarily supercedes them. So when we are done, things are safely & reliably left just as they were before the script ran.
  
==Enabling write access to the file system==
+
* In the other way, call it Type B, You submit an http request to a cgi on their server, and you supply the IP you want the ddns service to use, usually via query string arguments.
  mount -o remount,rw /
+
If you have a choice, this method is optimal for the Pre since it allows us to take advantage of built in features of pppd and doesn't matter if the ppp0 (evdo) connection is currently the default or only route at that moment. (Doesn't matter if you happen to be near, and using, a wifi connection at the time the script runs.)
  
==Obtain the Update URL provided by your service==
+
If you have the option to use either method (such as with DynDNS.org), try to use Type B.<br>
For  http://freedns.afraid.org, log in, and find the 'Direct Update URL' for your dynamic DNS entry. Mine looks like this:
+
In the particular case of the Pre, it's simpler and may be a little more reliable.<br>
  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.
+
==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, novaproxy, or using the homebrew on-device Terminal app.
 +
* This page assumes you have a Dynamic DNS service account with a service that provides URL based updating.
  
However, your service may differ, and require different information (example):
+
==Obtain the Update URL provided by your service==
  http://mydynamicdnsservice.com/?host=myhost.com&Ip=99.123.222.101
+
Some Type A examples:
 +
* [https://www.dyndns.com/developers/specs/syntax.html DynDNS.org/DynDNS.com]: <nowiki>http://username:password@members.dyndns.org/nic/update?hostname=yourhostname&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG</nowiki>
 +
* [http://freedns.afraid.org afraid.org]: <nowiki>http://freedns.afraid.org/dynamic/update.php?XXXXXXXXXXXX</nowiki>
  
 +
Some Type B examples:
 +
* [https://www.dyndns.com/developers/specs/syntax.html DynDNS.org/DynDNS.com]:<nowiki>http://username:password@members.dyndns.org/nic/update?hostname=yourhostname&myip=ipaddress&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG</nowiki>
 +
* [http://www.dnsmadeeasy.com/s0306/res/ddnsc.html dnsmadeeasy] <nowiki>http://www.dnsmadeeasy.com/servlet/updateip?username=YOURUSERNAME&password=YOURPASSWORD&id=DNSRECORDID&ip=YOURIPADDRESS</nowiki>
 +
* [https://joker.com/faq/content/11/427/en/what-is-dynamic-dns-dyndns.html?highlight=dynamic%20dns joker.com]: <nowiki>http://svc.joker.com/nic/update?username=YOURUSERNAME&password=YOURPASSWORD&hostname=YOURHOSTNAME&myip=YOURIPADDRESS</nowiki>
  
This example doesn't require the caller to be from the new target IP address, and won't need the routing entries.
+
==Enable write access to the root file system==
 +
<nowiki>mount -o remount,rw /</nowiki>
  
 
==Update your service whenever your ppp0 (EV-DO) IP address changes==
 
==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.
+
pppd will do this for us automatically by creating a script in the /etc/ppp/ip-up.d/ directory called 09update-ddns. So,
 +
<nowiki>vi /etc/ppp/ip-up.d/09update-ddns</nowiki>
  
This is the script for the first example:<br>
+
Then write whichever of these scripts applies to your provider.
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.
+
 
 +
Type A:
 
  <nowiki>
 
  <nowiki>
 
#!/bin/sh
 
#!/bin/sh
# pppd provides IFNAME and IPREMOTE for us
+
# pppd provides $IFNAME and $IPREMOTE
 
ip route add default via $IPREMOTE dev $IFNAME metric 1
 
ip route add default via $IPREMOTE dev $IFNAME metric 1
wget -qO- http://freedns.afraid.org/dynamic/update.php?ZzYyXxWwUuTtSsRr==
+
curl -s --retry 6 "http://MYUSERNAME:MYPASSWORD@members.dyndns.org/nic/update?hostname=MYHOSTNAME&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
 
ip route del default via $IPREMOTE dev $IFNAME metric 1
 
ip route del default via $IPREMOTE dev $IFNAME metric 1
 
  </nowiki>
 
  </nowiki>
  
This is the script for the second example:<br>
+
Type B:
Use this one if you need to or want to supply the IP yourself to the dynamic dns service.
 
 
  <nowiki>
 
  <nowiki>
 
#!/bin/sh
 
#!/bin/sh
# pppd provides IPLOCAL for us
+
# pppd provides $IPLOCAL
wget -qO- http://mydynamicdnsservice.com/?host=myhost.com&Ip=$IPLOCAL
+
curl -s --retry 6 "http://MYUSERNAME:MYPASSWORD@members.dyndns.org/nic/update?hostname=MYHOSTNAME&myip=${IPLOCAL}&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
 
  </nowiki>
 
  </nowiki>
  
 
==Make this script executable==
 
==Make this script executable==
  <nowiki>
+
  <nowiki>chmod 755 /etc/ppp/ip-up.d/09update-ddns</nowiki>
chmod 755 /etc/ppp/ip-up.d/09update-ddns
 
</nowiki>
 
 
 
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 /
 
 
 
* by raeb
 
* big thanks to  dreadchicken's tutorial
 
 
 
==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.
 
 
 
<nowiki>
 
#!/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
 
</nowiki>
 
 
 
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:
 
 
 
<nowiki>
 
less /media/internal/ppp_env.txt
 
[...]
 
wget: bad address 'svc.joker.com'
 
</nowiki>
 
  
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.
+
==Remount the root file system as readonly==
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.
+
<nowiki>mount -o remount,ro /</nowiki>
  
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:
+
==Notes==
 +
* The title of this document says "wget" yet "wget" is not used anywhere in it.
 +
Wget on the Pre is just a busybox built-in and lacks the retry feature we need.
 +
Since curl is also shipped as a stock part of the Pre's OS, and since it's
 +
the full-featured real curl program including --retry,
 +
it's simpler and costs us nothing to just use that instead of writing a retry loop around the fake wget in the shell script.
  
<nowiki>
+
== ==
#wget -O - "http://svc.joker.com/nic/update?username=MYDDNSUSERNAME&password=MYDDNSPASSWORD&hostname=pre.mydomain.net&myip=${IPLOCAL}" >>$L 2>&1
+
* raeb
curl --retry 6 http://svc.joker.com/nic/update?username=MYDDNSUSERNAME&password=MYDDNSPASSWORD&hostname=pre.mydomain.net&myip=${IPLOCAL}" >>$L 2>&1
+
* dreadchicken
</nowiki>
+
* [[User:Bkw|Bkw]] 13:09, 1 November 2009 (UTC)
 
 
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)
 
 
 
<nowiki>
 
#!/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
 
</nowiki>
 

Latest revision as of 12:54, 5 November 2009

Preamble

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), using only software that comes installed stock on the Pre (other than the small shell script you will write) and not requiring a daemon process running all the time to monitor the connection (other than pppd itself, which is what makes the connection in the first place, not anything extra).

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 solution that doesn't require an always-on daemon or installing any additional software, this guide may be for you.

There are many ddns service providers and most of them offer some way to update your ddns entry via URL. There are two main ways that a ddns service provider obtains your dynamic IP from you. Some providers use one way, some use the other way, some provide both methods and allow you to use whichever way is more convenient for you.

  • In one way, call it Type A, You submit an http request to a cgi on their server, and their server uses the IP that the request came from.

One potential advantage to this method (for other environments besides the Pre) is that the url is static. It doesn't need any variables, and your script or program doesn't need to figure out what your current IP is when it runs. This can be good for PC's behind NAT routers that don't have a built-in ability to update your particular ddns service.

However on the Pre this advantage is outweighed by the need to ensure that this request always goes out via the evdo connection even if you happen to be near a wifi access point which would be used otherwise. This is so that the ddns service always gets your evdo IP, never the IP of any wifi access points you might happen to be near at the time. The evdo connection is the only IP that will be useful for remotely accessing the Pre.

To do that, on the Pre, we momentarily make the ppp0 connection the highest priority by adding a routing table entry just before updating the ddns service, and remove it immediately after. This does not affect any of the existing routing table entries of the moment, just temporarily supercedes them. So when we are done, things are safely & reliably left just as they were before the script ran.

  • In the other way, call it Type B, You submit an http request to a cgi on their server, and you supply the IP you want the ddns service to use, usually via query string arguments.

If you have a choice, this method is optimal for the Pre since it allows us to take advantage of built in features of pppd and doesn't matter if the ppp0 (evdo) connection is currently the default or only route at that moment. (Doesn't matter if you happen to be near, and using, a wifi connection at the time the script runs.)

If you have the option to use either method (such as with DynDNS.org), try to use Type B.
In the particular case of the Pre, it's simpler and may be a little more reliable.

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, novaproxy, or using the homebrew on-device Terminal app.
  • This page assumes you have a Dynamic DNS service account with a service that provides URL based updating.

Obtain the Update URL provided by your service

Some Type A examples:

  • DynDNS.org/DynDNS.com: http://username:password@members.dyndns.org/nic/update?hostname=yourhostname&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG
  • afraid.org: http://freedns.afraid.org/dynamic/update.php?XXXXXXXXXXXX

Some Type B examples:

  • DynDNS.org/DynDNS.com:http://username:password@members.dyndns.org/nic/update?hostname=yourhostname&myip=ipaddress&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG
  • dnsmadeeasy http://www.dnsmadeeasy.com/servlet/updateip?username=YOURUSERNAME&password=YOURPASSWORD&id=DNSRECORDID&ip=YOURIPADDRESS
  • joker.com: http://svc.joker.com/nic/update?username=YOURUSERNAME&password=YOURPASSWORD&hostname=YOURHOSTNAME&myip=YOURIPADDRESS

Enable write access to the root file system

mount -o remount,rw /

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

pppd will do this for us automatically by creating a script in the /etc/ppp/ip-up.d/ directory called 09update-ddns. So,

vi /etc/ppp/ip-up.d/09update-ddns

Then write whichever of these scripts applies to your provider.

Type A:

#!/bin/sh
# pppd provides $IFNAME and $IPREMOTE
ip route add default via $IPREMOTE dev $IFNAME metric 1
curl -s --retry 6 "http://MYUSERNAME:MYPASSWORD@members.dyndns.org/nic/update?hostname=MYHOSTNAME&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
ip route del default via $IPREMOTE dev $IFNAME metric 1
 

Type B:

#!/bin/sh
# pppd provides $IPLOCAL
curl -s --retry 6 "http://MYUSERNAME:MYPASSWORD@members.dyndns.org/nic/update?hostname=MYHOSTNAME&myip=${IPLOCAL}&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
 

Make this script executable

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

Remount the root file system as readonly

mount -o remount,ro /

Notes

  • The title of this document says "wget" yet "wget" is not used anywhere in it.

Wget on the Pre is just a busybox built-in and lacks the retry feature we need. Since curl is also shipped as a stock part of the Pre's OS, and since it's the full-featured real curl program including --retry, it's simpler and costs us nothing to just use that instead of writing a retry loop around the fake wget in the shell script.

  • raeb
  • dreadchicken
  • Bkw 13:09, 1 November 2009 (UTC)