Mar 112012
 

Recently I had some issues with my free DNS service, it wasn’t updating my DNS so I couldn’t access my server remotely.
After this happened a few times, I decided to modify one of the configuration files so that it would email me my external IP address each time the PPP connection came up. This ensured that I would get the latest IP address emailed to me ASAP.

What You Will Need :

Sendmail or equivalent on the linux box that you doing this on.
The PPP connection needs to be on the linux box also for this tutorial, however I will write up a guide that uses an external website instead later on.
A commandline mail sending program, I have used mailx in this example, which is symlinked to mail.

How To Do It :

To do this, I added a file in this directory ( on my Debian System ) –

/etc/ppp/ip-up.d/

which I have named “EmailIP”.
Scripts in this directory are run when the ppp connection goes up.

The file contains the following line which does the gruntwork

echo Connection has come up - New IP Address : `ifconfig ppp0 | grep inet | awk -F' ' '{ print $2 }'|awk -F: '{print $2}'` | /usr/bin/mail -r <From@example.com> -s IP-Address <Email@example.com>

What that command does is pipe the text “New IP Address : ” followed by the output of ifconfig ppp0 which is then grepped down to the inet line, and then awked down to the actual IP address and pipe it into the mail command which can send an email via sendmail or whatever mail daemon you have installed.
The sendmail command has the following parameters specified –
-r : specifies the address that the email appears to be coming from (From@example.com in the example)
-s : specifies the subject of the email (IP-Address in the example)
Email Address (Email@example.com in the example)

Then once you have the script in place, when the ppp connection goes down then comes back up, you should get an email to the email address you specified with the text “Connection has come up – New IP Address : <Your New IP Address>

Share

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

This site uses Akismet to reduce spam. Learn how your comment data is processed.