How to set up a Linux client for 2myDNS.com
David Mills, (mail to:d.mills at tiscali dot fr)
Changelog:
12/11/2003 Added cable modem section and cleaned up a bit.
15/04/2005 Added fix for cable modem script
The purpose of this document is to illustrate the different methods of updating the 2mydns database using a Linux client.
A Dynamic DNS client basically does 3 things, in this order:
- It detects when your IP address changes.
- It determines your new IP.
- It sends this information to the server so that the DNS register is updated.
- Detecting a change in IP
In the case of a dial-up or DSL connection, this only happens when you
connect to the Internet, so all we have to do is tell the computer to
update the information each time we connect.
- Determining the new IP
There are two possibilities here, either the dial-up utilities tells us the new IP (as in the case of pppd) or they don't.
In the first case, we can just pass it on, but in the second we need to get it from the system, which is where ifconfig, grep and sed come in very handy.
- Sending the new IP to the 2myDNS servers
The technical documentation tells us that the client simply calls a
designated asp script, passing it the parameters required to update a specific
domain. To this end we will be using the wget utility
In this section we'll assume that you already have a working ppp client
which you use to connect to the Internet. If this is not the case, the PPP Howto (http://www.tldp.org) should be enough to get you going.
This is the Heinz 57 solution, since any Linux distribution will come
with it(with the possible exceptions of the slackware install floppies
and the tomsrtbt single floppy rescue disk).
If you're using the modem-lights applet under gnome, providing that you
can connect using the applet, and that the it is configured to use /usr/sbin/ppp-on to connect, this method will also work for you.
The ppp daemon (pppd) calls the /etc/ppp/ip-up script once a connection is
established, so it's this file we're going to edit.
Open /etc/ppp/ip-up in your favorite text editor (the job can be done with 'cat', but it's not recommended :-)).
Now, when pppd calls this file it kindly passes on several parameters,
notably
the local and remote addresses of the ppp connection, so that all
that's left to do is add the local IP address (parameter number 4) to
our URL and pass the URL to wget.
The code you have to add looks like this:
echo "Setting up dynamic dns address" > /dev/tty0;
wget "http://dyn.2mydns.com/dyn.asp?username=myname&password=mypass&hostname=myname.2myip.com&myip=$4" -O /dev/null;
|
The '-O /dev/null' at the end of the 'wget' command is to send the received file to the great black hole in your computer (/dev/null),
so that your machine doesn't get cluttered up with redundant files. Of
course you could use this file for error handling, but this isn't
essential in the present case.
And that's it, the next time your machine connects to the web your 2mydns account will/should be updated automatically.
With gnome-ppp the advantage is that you can specify the script to be launched when
you connect. On the other hand, getting the IP is up to you although this isn't a great problem when you know where to look.
To start with, paste the following into your text editor of choice and save it somewhere.
#!/bin/bash
#First of all get the IP
IP=`/sbin/ifconfig ppp0 | grep "inet addr:" | sed -e 's/^.*inet addr://' -e 's/ .*$//'`;
#Then pass it along
wget
"http://dyn.2mydns.com/dyn.asp?username=myname&password=mypass&hostname=myname.2myip.com&myip=$IP"
-O /dev/null;
|
The first line gets the info from your computer about the ppp0
interface (the one that's generally used for Internet access), then it
strips everything except the line containing the IP address (the grep bit), and finally it removes what's around the address (the sed bit), before passing it to a wget statement identical to the one used in the pppd case. Now make it executable (`chmod +x name_of_file` in a console, or right click and click on properties in nautilus).
Now all you need to do is get gnome-ppp to launch it. To do this, open
gnome-ppp, select the account you use to access the Internet, and click
on Account->Edit, then go to the 'PPP' tab and enter the name of the
file you just created in the 'Run Program After Connect' text box.
Click on OK. Now when you connect to the Internet, your 2myDNS Account
should be updated automatically.
Configuring Kppp is
very much like configuring gnome-ppp, in that you have to create a
script and then tell Kppp to access it, So I'm only going to cover the
part which differs.
To configure Kppp so that it accesses the script after each connection
has been established, You start by clicking the 'setup' button, then
you select the account you use to access the Internet and click on
'Edit' and then move to 'Execute' tab. Here you enter the name of your
script in the 'upon connect' text box, and click on 'OK' twice to get
back to the connection window. Kppp should now be configured to update
your 2myDNS account automatically.
Cable modems
present a special case in that they don't need initialising through a
ppp connection like most other ways of accessing the web, so we can
just transmit our IP using a bootscript.
To do this, copy the following to a file (2myDNS.sh would be a nice name) and make it executable:
#!/bin/bash
#First of all get the IP
IP=`/sbin/ifconfig eth0 | grep "inet addr:" | sed -e 's/^.*inet addr://' -e 's/ .*$//'`;
#Then pass it along
wget
"http://dyn.2mydns.com/dyn.asp?username=myname&password=mypass&hostname=myname.2myip.com&myip=$IP"
-O /dev/null;
|
Then copy the file to /etc/rc.d/init.d, and symlink to it from /etc/rc.d/rc.3 and /etc/rc.d/rc.5 naming the links S992myDNS, then just run the script or reboot.
The above should work on all Red Hat and Debian based systems (Gentoo excluded).
First of all thanks to Paul Newcum for his help in teaching me about the workings of cable modems.
A lot of effort has been put into this document to make it simple but
accurate and complete but not excessively long. Nevertheless, no
liability will be assumed by the author under any circumstance, so you
use the information contained here at your own risk. Please feel free
to e-mail me any suggestions, corrections or general comments about the
document so I can improve it.
(Thanks to Daniel Lopez Ridruejo for the outline of this disclaimer)
This guide is copyrighted 2003 David Mills.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts.