Re: Finding the external IP on a DSL router?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On November 23, 2004 07:58 pm, Edward wrote:
> > #!/bin/bash
> > #
> > # 11-01 Pete Nesbitt
> > # script to check if eth0's IP has changed.
> > #
> >
> > DATE=`/bin/date`
> >
> > # set variables for email
> > EMAIL="user@xxxxxxxxxx user@xxxxxxxxxxxxxxx"
> >
> > # a file to hold the previous IP
> > OLDIP="/usr/local/scripts/check_ip/oldip.txt"
> >
> > # check for the current IP
> > CURRENT_IP="`/sbin/ifconfig -a|/bin/grep -A 2 eth0|/bin/awk '/inet/ {
> > print $2 }'|/bin/sed -e s/addr://`"
> >
> > # compare to new IP to last IP
> > if [ "`/bin/cat $OLDIP`" != "$CURRENT_IP" ]; then
> >
> > # next part is all one line
> >   /bin/echo "The IP was reset at $DATE (ea 20 min.). The OLD IP was `cat
> > $OLDIP`. The New IP is $CURRENT_IP. You must update
> > yi.org and hostname."|/bin/mail -s "New IP Address" $EMAIL
> > # end if the long line
> >
> > # copy the new IP to the old IP
> >   /bin/echo "$CURRENT_IP" > $OLDIP
> > fi
> >
> > exit
>
> Just a side note Pete - I'm by no means a scripter, but where does the
> above script find the router's external IP address?
>
> What you said before holds true - if you set up dyndns or equivalent,
> you can ping the address to get the outside ip, but your script (to my
> untrained eyes), seem to grab the IP information from ifconfig.
>
> If I run ifconfig -a, it shows a local address of my gateway as the inet
> address on eth0, and my outside address on ppp0.
>
> But if he's using a router, would his gateway not be a local address?
>
> You're probably right though, as I don't know much about these things,
> but I just want to make sure.
>
> Regards,
> Ed.


Hi Ed,
You raise some interesting questions. This may come down to which DSL 
technology is in place.

My DSL connection (always-on) comes in to a DSL modem (telco provided) that 
has a 10 Mb Ethernet port on the inside. That feeds  into a Linux box which 
has 3 nics (InterNet, LAN, DMZ) and acts as a fireqwall/gateway. If it is a 
hardware router, well then that is a different story, I guess I always 
presume Linux:-) 

My outside is eth0, so ifconfig can pull the IP from it. I have almost no 
experience with ppp, but if your using it on DSL then it must be a 
connect-on-demand, not an always-on setup, which would make pulling the IP 
from inside difficult, unless you initiated a external link first.

This may come down to another "need more info".

-- 
Pete Nesbitt, rhce

-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux