LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Ubuntu Server needs to inform me of a new IP address when it changes (https://www.linuxquestions.org/questions/linux-newbie-8/ubuntu-server-needs-to-inform-me-of-a-new-ip-address-when-it-changes-4175458830/)

JoseCuervo 04-19-2013 09:58 PM

Ubuntu Server needs to inform me of a new IP address when it changes
 
I am running an Ubuntu gaming server on my home network, behind a router and firewall. My ISP is Verizon, and my external IP address changes from day to day, rarely going a week the same. This makes it difficult for other people to access my server consistently, and requires me to get a complaint, go home, check my IP, and then tell them all. Verizon doesn't think I pay enough to have a static IP, and I agree.

How can I get Ubuntu to check what the external IP is, and then forward that information in the form of a text or email if the results have changed? I have rudimentary Ubuntu skills, and my reaction was to write a script checking the IP and then sending the updated address to an (e)mailing list of recipients. I would then have cron run the script every ten minutes or so.

1: Is that idea feasible?
2: Would someone help me write that script if so?
3: What is a better idea?

casualfred 04-19-2013 11:07 PM

I use a similar script on a server at my house. There are a couple parts of the script that need to be set up first beforehand, like the mutt email program. Here is the script:
Code:

#!/bin/bash

EMAILLIST="johnboy@yahoo.com jeff@gmail.com 8829833382@txt.att.net"
NEWIP=`curl http://ipecho.net/plain; echo`
OLDIP=`cat /tmp/currentip`

if [[ "$NEWIP" != "$OLDIP" ]]; then
MESSAGE="`date +\"%m-%d-%Y_%R\"` Server's IP changed from $OLDIP to $NEWIP"
echo $MESSAGE > /tmp/ipsmg
mutt -F /home/casualfred/.muttrc -s "Server IP Change" $EMAILLIST < /tmp/ipmsg && echo $NEWIP > /tmp/currentip
fi

Here is a handy guide for setting up mutt with gmail - it's pretty easy:
http://lifehacker.com/5574557/how-to...ent-with-gmail

Here is another link about sending texts to your phone via email:
http://www.email-unlimited.com/stuff...l-to-phone.htm

I found that since I have AT&T (but used to be Cingular) I can send texts to my phone by sending an email to mynumber@txt.att.net or mynumber@cingularme.com. It would depend on your carrier.

So, there's some ideas for you :)

michaelk 04-20-2013 03:23 AM

You can use a free dynamic IP service like dyndns or noip. Your URL (e.x. something.dyndns-server.com) is updated with the IP address via a client that either is built into the router (typically dyndns) or runs on your server.


All times are GMT -5. The time now is 05:02 PM.