What is my IP?

Make you linux machine inform you if external IP address is changed.

By Kostas Koutsogiannopoulos

Lets say that you have a linux machine in a location with non static IP address but you need to access it from outside.

The following script is a quick way to avoid using a dynamic dns service. You can schedule it in a cron job and it will sent you an e-mail with the new IP address if it is changed:

OUTSIDE_IP=$(dig +short
LAST_IP=$(cat /root/last_ip.txt)
if [ "$OUTSIDE_IP" != "$LAST_IP" ]
 echo "OUTSIDE_IP has changed"
 echo $OUTSIDE_IP > /root/last_ip.txt
 echo "$OUTSIDE_IP" | mail -s "IP address is changed"
echo "`date +%Y-%m-%d\ %T` $OUTSIDE_IP" >> /root/last_ip.log

View epilis's profile on LinkedIn Visit us on facebook X epilis rss feed: Latest articles