External IP script
Posted: January 15th, 2012, 10:29 am
Hi all
Just a quick tip/trick I thought I'd pass on.
As most of us don't have an ISP kind enough to supply us with a static IP the question of how to SSH to our server from outside the home network poses a problem. While there are services that provide DDNS like DynDNS.org they charge money and I'm tight! Besides I don't need to log on remotely that often.
I have written the following script which serves me well, basically it checks to see if my external IP has changed and sends me an e-mail when it does.
Make the script executable
chmod a+x MyIP.sh
Create a blank log file, I've called mine MyIP.log. Imaginative I know. It will populate the first time the script is run.
Set the script as a cron job to execute at an interval of your choice.
Job done.
In order to SSH in from the outside world you will need to make sure your router is forwarding the appropriate port (22 in my case) to your server.
Then just tell putty your newly discovered IP.
Hope someone finds this of use.
Dunk
Just a quick tip/trick I thought I'd pass on.
As most of us don't have an ISP kind enough to supply us with a static IP the question of how to SSH to our server from outside the home network poses a problem. While there are services that provide DDNS like DynDNS.org they charge money and I'm tight! Besides I don't need to log on remotely that often.
I have written the following script which serves me well, basically it checks to see if my external IP has changed and sends me an e-mail when it does.
Code: Select all
#!/bin/bash
#
# PURPOSE: e-Mail me my external IP on change.
#
#
new=$(wget -qO - http://cfaj.freeshell.org/ipaddr.cgi)
if grep -q $new /home/myhomedir/MyScripts/MyIP.log
then
echo "No change"
else
echo $new > /home/myhomedir/MyScripts/MyIP.log
/usr/sbin/ssmtp my@email.co.uk </home/myhomedir/MyScripts/MyIP.log
fi
Make the script executable
chmod a+x MyIP.sh
Create a blank log file, I've called mine MyIP.log. Imaginative I know. It will populate the first time the script is run.
Set the script as a cron job to execute at an interval of your choice.
Job done.
In order to SSH in from the outside world you will need to make sure your router is forwarding the appropriate port (22 in my case) to your server.
Then just tell putty your newly discovered IP.
Hope someone finds this of use.
Dunk