Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can I get a message when my public dynamic ip address changes ?

Status
Not open for further replies.

NewtownGuy

Technical User
Jul 27, 2007
146
US
How can I get a message when my public dynamic IP address changes ? I need the message with as small a delay as possible from the moment when the public IP address changes. I'm running Ubuntu Server 10.04 LTS.

I assume my machine has to be the Internet gateway router and have two network ports so its DHCP client can be used. It could be useful if my hardware router could send me the message instead, although I realize that this would open up a multitude of questions about the router, which is why I assumed my Linux box must serve as the router.

I tried running tracert to an external web site to try to discover my public IP address, but it does not. Why not ?

Thank you in advance.

 
Assuming you have a router provided by your ISP your server IP is not going to change, the external IP is applied to the router your server will have a 192.168.0.0/16 address from the private IP range.

Why not just use one of the Dynamic DNS providers such as Dyn.com, many cable/broadband routers have Dynamic Dns service updaters built in to them.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
I can't go into details but I need to instantly perform a number of steps when the public IP address changes. So I need to instantly know when the IP address changes, and I need to know what the new public IP address is. So the question is, what can I do to instantly find out when the public IP address changes, and how can I instantly find out what the new public IP address is ?

Currently, none of the public IP addresses are of the form 192.x.y.z, but tracert does not give me the same address that, for example, does.

I've considered pointing the dnydns function in my router to my own server, but how would I do that and what service would I need to run ?
 
There are two subtleties to this:

...1) I can't use a dyndns provider, but maybe I can set up my own (how?).

...2) I need to know ** instantly ** that my public IP address has changed, and what the new public IP address is. I can't just run a script that somehow checks once an hour. That's why I'm wondering if a Linux box with two NICs should be the router since its DHCP client should know the moment the IP address changes because the lease runs out.

In a router, how quickly does a dyndns updater know that the public IP address has changed ?

 
You could just script something like:

Code:
/usr/sfw/bin/wget -O  [URL unfurl="true"]http://www.biranchi.com/ip.php[/URL] |cat ip.php
83.152.131.124

Which will return your public @IP

Obviously I can't comment if biranchi will be too amused if you are constantly requesting your IP but there are many such sites so maybe you could set up a list of them and cycle around processing then accordingly .....

Or if you can find someone out there that will allow you to ping them you can do something like:

Code:
$ ping -r 1 somedomain.com | grep -u Route| tail -1
    Route: 83.152.131.124

With either of the above you now have your @IP to do something with ....

IHTH

Laurie
 
Thank you, but it's not working for me.

I tried the wget example, using just 'wget ...' at the beginning, but I don't get anything. I touched ip.php since I did not have that file, but I still don't get anything. No errors, no data.

I tried the ping example using google.com as the target, but I get an invalid argument.

Please double-check.

 
A: Your public IP will probably only change when you disconnect and reconnect your router Or when the DHCP lease runs out. And there's every chance you will get the same IP at that point.

B: Why not ask your ISP if they will provide you with a static IP? (that's all I did)

C: Write a bash script to query whatsmyip.org and extract the IP from the returned page code.

D: have a read at
E: via CURL


Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Thank you, but there's more to the story...

The problem is that I must assume any public IP address can come under DDoS attack. Hopefully, the larger the site, the more likely they can withstand the attack. But not mine, so I must avoid the attack.

That rules out my having a static IP address, or keeping a particular dynamic IP address very long. And, it rules out relying on a small site to tell me my IP address because the small site could be taken out by a DDoS attack and that would interfere with my site. It rules out using dyndns providers. Think of all the webcams that would go down if their dyndns provider comes under attack...

I always thought it would be easy to find out my own public IP address directly, but apparently not, especially since not even tracert tells me it.

Any suggestions ?

How does my router know my public dynamic IP address ? Is it simply because it's using a DHCP client with my ISP ?

 
I think you are worrying about denial of service attacks unecessarily.

I have been running webservers for over twelve years and some of our clients are political and ecological activists/lobbyists in East Africa and Germany and have yet to be inconvenienced, never mind taken off-line by such an attack.

The server firewall will block IPs that are sending repeated requests within a set timescale (60/10 mins)

The sites must be very low traffic and very low profile to even contemplate running them on an asynchronous "home connection", unless you have a synchronous 64k bit leased line of course.

Take it from me, on a broadband or cable connection, you are at more risk of being taken off-line by a search engine doing a fast or "deep" crawl than you are by malicious intent.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
1) No need for me to re-check!
I rarely post anything that I have not tested first and in the case of both the wget and the ping what you see are the result of my live testing before I responded (but with the Ping "domain" changed and the @IP changed to protect "my server and @IP")

2) Just saying "It's not working for me" is not helping us help you.
I assume that you have wget installed? (though I'm beginning to doubt what OS you are running as you later mention "tracert" which is Windows? "traceroute" is Unix/Linux but maybe your testing on Windoze and not Linux as I thought and that may be the problem with your wget and your ping command too most likely).

3) Just running and trying to hide from DDoS attacks is not the solution! Just configure your firewall correctly to detect and block them as they occur.

4) The fact that your not giving much away about why you need track your public @IP and that you have fears that it will come under attack makes me think that your doing something that maybe you shouldn't be "well not from a home network" .... but that's completely up to you ;)

I really can't help you any further.

However if it was me I'd be looking into identifying my make of BB Router and looking for a command-line query or where possible enable snmp allowing me to query it's external @IP directly, or as I have already shown a simple script to ask some host out on the internet to tell me then use that to do the jiggery-pokery you seem to need to do.

I hope you manage to resolve your problem.

Laurie.
 
Hi tarn,

Here's my OS (Ubuntu Server 8.04 LTS):

root@xxxx:~# uname -a
Linux xxxx 2.6.24-19-server #1 SMP Wed Jun 18 15:18:00 UTC 2008 i686 GNU/Linux

tracert works for me:

root@xxxx:~# tracert google.com
traceroute to google.com (74.125.113.147), 30 hops max, 40 byte packets
1 192.168.192.1 (192.168.192.1) 0.551 ms 0.607 ms 0.664 ms
2 73.175.236.1 (73.175.236.1) 7.756 ms 12.075 ms 12.271 ms
<truncated>

But my actual public IP address, according to ipchicken.com, is 76.23.xxx.yyy, and that IP address does not appear anywhere in the tracert report.

Yes, I have the latest version of wget according to apt-get. When I use this command:

wget -O |cat ip.php

There aren't any error messages, but I get a zero-length file, ip.php, in the folder from which I executed it. Previously, I executed 'touch ip.php' because otherwise I get an error message, 'cat: ip.php: No such file or directory'.

Some things are mission-critical.

Cheers.
 
Ok I have to admit I know nothing about Ubunto so indeed it appears to have "tracert".

So if you go via a browser to do you see your @IP?

If so then do a simple wget and see what's returned in the ip.php file that wget recieved.

Maybe the -o ("output" flag) is different on your version ?


Laurie
 
and that IP address does not appear anywhere in the tracert report.

Your external IP will NOT appear in a traceroute chain, simply because a traceroute is a outgoing packet trace and the INTERNAL IP of your router is the first "hop" from your machine on it's outward path.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Hi Laurie,

Yes, I get the correct public IP address when I go to the site.

And yes, I get a file with the proper IP address when I do a simple wget.

Cheers,

 
Hi Chris,

I checked the manual for tracert (Laurie: tracert on Ubuntu is supposed to be the same as traceroute -I), but I still don't understand why it does not report my public IP address in the 15 or so hops it takes to get to the destination. I don't even see an IP address where the left-most digits are the same as mine.

Other than relying on an outside agent to tell me my public dynamic IP address, is the only way to get it to get inside the DHCP client in my router ? If so, how would I do that ?

 
but I still don't understand why it does not report my public IP address in the 15 or so hops it takes to get to the destination
Ok, I'll try it in a different way.

The hops are only the RECEIVING IP/host name. The packets are accepted in then the receiving end acknowledges that a successful delivery was made. It is the acknowledgement that is passed back to the traceroute request NOT the transmission of the packets.

Your router external IP is the transmission address NOT the receiving address and it is the INTERNAL interface that sends the first acknowledgement.

Could be another candidate for one of my "Quick Tips" posts. :-D



Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
OK... Traceroute does not do what I wanted it to do.

So how do I get my public dynamic IP address without using an outside agent unless I can get into the DHCP client on my router ?

 
Ok last offer ....

I assume you can access your Broadband Router?

So go look at the routing table (there has to be an option to read/view it) look for the network link address (basically the next hop from your router external interface) .... mine is like this

Code:
0.0.0.0	0.0.0.0	86.132.122.1	ppp0

Now use your command for: ping -r 1 <yourGW address>

check your man page for "ping" if you still can't get it to work

Good luck.

Laurie.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top