On Thu, 18 Mar 2010 21:52:28 -0400
"Brad Tilley" <b...@16systems.com> wrote:

> There are ports that do this with more features, but I thought others
> might like to do it in base with no added software. I've been using this
> script since 4.2 and it works OK:
> 
> #!/bin/ksh
> 
> # Cron this script to run every X minutes. Written for OpenBSD.
> 
> # Get Current IP
> lynx -dump http://checkip.dyndns.org:8245/ | awk '{print $4}' | sed
> '/^$/d' > ip_new.txt
> 
> # compare new with old
> diff ip_new.txt ip_old.txt
> 
> # if different, send update
> if [ $? -ne 0 ]
> then
>   #echo "The IP has changed"
>   ip=$(cat ip_new.txt)
>   # Following two lines are optional. Log date of change and IP history.
>   date >> ip_date.txt
>   cat ip_old.txt >> ip_history.txt
>   curl --insecure
>   
> "https://user:p...@members.dyndns.org/nic/update?hostname=host.xxx&myip=$ip&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG";
> fi
> 
> # Whether a change has occurred or not, overwrite old with new
> cp ip_new.txt ip_old.txt
> 

I've done a similar thing by hacking /sbin/dhclient-script to hook
out from add_new_address().  I also suppress add_new_resolv_conf()
and reupping from /etc/resolv.conf.save found in the main section.
Suppressing update of resolv.conf is optional but it's useful
to have the dns pointed at the nameserver for the domain and
just leave it there.

The hook out has to then call nsupdate with the newip address.  
The advantage to this approach is that is driven off the event
of a new address by dhcp and not by polling.  

Dhu

Reply via email to