I wrote a bash script and appended to my crontab to query my IP address every minute, and if it is not the same with the previous query it sends me an e-mail to inform me for the IP address change. But there's a strange thing. As it queries constantly every minute for the IP address, from time to time ( very frequently )it sends me irrelevant IP addresses. What can be the reason for this?

enter image description here

  • what exactly is the cron job doing? what kind of ISP are you using? – michas Jul 14 '14 at 6:58
  • It just goes to one of the websites that I wrote url and asks what's my ip. It notes the response to a file. And continues checking every minute, if the value in the file and the newly queried are the same, it does nothing. If they are different from each other it sends my the new ip as email, it replaces the file with the new ip. But continues querying for a change every minute. The problem is that icanhazip or the other service does not respond with the same correct ip address although it is not the real ip. Why quering this frequently confuses the icanhazip services head? – ybaylav Jul 14 '14 at 7:31
  • Could it be, that your ISP does not provide to you a real, global IPv4 address, but only an IPv6 address? In this case, the access to IPv4 is done normally via a NAT-solution at the ISP. This explains perfectly the regular changing of the external seen IPv4 address. – jofel Jul 14 '14 at 8:28
  • Can you please post the actual cron job / script that you're using? – HalosGhost Jul 14 '14 at 8:28
  • 1
    We can't help unless we know what your script is doing. Please edit your question and include the script and the cronjob that launches it. – terdon Jul 14 '14 at 11:36

I suspect your ISP is running multiple proxy servers with load balancing, and these are the IPs of the proxy.

Web proxies wouldn't have any effect on SSH sessions. If you run who on the SSH server, it should show the IP that this session is coming from, which is your real public IP.

  • It may be true. – ybaylav Jul 14 '14 at 16:46

This behaviour can be perfectly explained if your ISP uses Carrier-grade NAT: Multiple users share a pool of few public IPv4 addresses.

Often, provider of mobile internet access (4G, ...) uses this technique.

As the IPv4 address room is mostly used/reserved, this is a cheap solution for ISPs to provide IPv4 access to their customers. Usually, you get still your own public IPv6 address range.

  • 1
    If this was the case, then I could not connect to one of the machines running under that modem via ssh using the frequently repeating IP. – ybaylav Jul 14 '14 at 8:57

Use traceroute or tracepath to get an idea what your real connection to that host is.

Given that those services really only output the source IP of your connection and you have no mistake in your script, you have some really strange routing setup. Either by yourself or by your ISP.

  • It is potentially from the ISP. It's a 4G modem and I'm(the machine) just having a dhcp ip from it. I did not do anything complicated as I'm abroad and living in a hotel room. – ybaylav Jul 14 '14 at 8:29

You mentioned that you use a 4G modem to establish a connection. Have you access to some logging output of this modem ?

It sounds like your modem loses the connection and establishes a new one with also a new IP address.

One of many possible reasons could be, that your cell tower has to handle to much user. Or there is another device which interferes with yours, etc

  • But my SSH sessions don't drop while the e-mails keep coming. So I don't find this logical. – ybaylav Jul 14 '14 at 9:48

Your ISP may by proxying/caching HTTP requests. But icanhazip.com supports HTTPS which, like SSH, your ISP can't proxy. So try changing the script to

curl https://icanhazip.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.