This is an old script that I use on OpenBSD to update my ddclient hostnames. The script should run with minor modifications on Linux.
#!/bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
IPFILE=/root/scripts/ipcheck.ip
INTF=tun0
MAILRCPT="yourmail"
MAILSUBJECT="DDclient update"
IP=`ifconfig $INTF | grep "inet " | grep -v inet6 | awk '{print $2}' |
sed 's/addr://'`
if [ -f $IPFILE ]; then
OLDIP="`cat $IPFILE`"
fi
if [ "$IP" != "$OLDIP" ]; then
echo $IP > $IPFILE
/usr/bin/logger -t ipcheck_ddclient new IP address -- changed to $IP
/sbin/ifconfig -a | mail -s $MAILSUBJECT $MAILRCPT
/usr/local/sbin/ddclient -daemon=0 -syslog -use=ip -ip=$IP
fi
If you are unable to get your public IP from a local interface then you can use dyndns.org.
wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'
