DynDNS update script
I recommend using the ddclient
utility to update your hostname when using a dynamic IP address with http://www.dyndns.org/ or similar services.
Old notes
I wrote the following script on my Red Hat Linux system to update my dyndns.org hostname when my
dynamically-assigned IP address changes. The script makes use of nslookup, lynx, and dyndnsupdate.
Since I am using Network Address Translation with my router, and am
using a private class C IP address internally, I use the http://whatismyip.com/ Web site to
determine my external (router's) IP address.
I am also running BIND as a caching nameserver; I restart BIND when my
IP address changes to clear the DNS cache.
Since my IP address changed very infrequently, I am using DynDNS'
"static DNS."
#!/bin/sh
# This script uses
"dyndnsupdate" available at http://www.bebits.com/app/2927
# HOSTNAME is your DynDNS
hostname
HOSTNAME=your_hostname.dyndns.org
# NSLOOKUP is the current DNS
entry for your DynDNS hostname
NSLOOKUP=`/usr/bin/nslookup -sil
$HOSTNAME | tail -2 | head -1 | cut -d" " -f2`
# CURRENT_IP is your router's
current IP
CURRENT_IP=`/usr/bin/lynx -dump
http://www.netins.net/dialup/tools/my_ip.shtml
| grep -A2 "Your current IP Address is:" | tail -n1 | tr -d ' '`
# Is CURRENT_IP returning
"unknown"?
if [ "$CURRENT_IP" = "unknown" ]
; then
exit
fi
# Is our current IP in the
DynDNS DNS records? If not, update them.
if [ "$NSLOOKUP" !=
"$CURRENT_IP" ] ; then
/sbin/dyndnsupdate
-a $CURRENT_IP -h your_hostname.dyndns.org -m \
your_hostname's_mail_exchange.dyndns.org
-s statdns \
-u dyndns.org_username:dyndns.org_password
# Flush local DNS
cache of $HOSTNAME
/sbin/service named
restart
fi
Back to brandonhutchinson.com.
Last modified: 01/26/2004