I have a home network which I have SSH set up on. I would like to be able to dial my home network remotely but my ip address changes at least once a day. I called my ISP to see if they can provide me with a static IP address, but they charge a lot of money to lease static IPs to compensate for the assumed increase in bandwidth of running a server.
I don't plan on running a game server or anything that requires a lot of bandwidth so I don't want to spend the extra money.
So my plan was to create a simple script that would query my external IP address, echo it to a file and then email the contents of that file to myself at regular intervals.
I've gotten the first part of the script working and it does echo my external IP. However, the second part which would then email the script to myself I can't figure out. Then the third part I guess would be to run a cron job that will execute the script.
Here is my script so far.
When I execute the script, my IP address is echoed to ~/ipaddress. But mail is not being sent to my email address. Do I need to configure mail? I installed 'mailutils' and set the server settings to 'internet site' since I use gmail. Is that incorrect?
CURRENT_IP=$(wget http://www.whatismyip.org -O - -o /dev/null)
if [ -f $IPFILE ]; then
if [ "$CURRENT_IP" != "$KNOWN_IP" ]; then
echo $CURRENT_IP > $IPFILE
MAIL_SUBJECT="IP address at home"
MAIL_BODY="The IP address at home has been changed to $CURRENT_IP. Update SSH client now."
echo $MAIL_BODY | mail -a "$MAIL_FROM" -s "$MAIL_SUBJECT" -c firstname.lastname@example.org
logger -t ipcheck -- IP changed to $CURRENT_IP
logger -t ipcheck -- No IP change