We were recently setting up a linux server to integrate with a partner of ours, and we found that it was unable to connect to the remote server. Our first suspicion was that our partner was blocking any ip addresses that were not in a white list, and a couple of quick emails confirmed this to be the case. We just needed to tell them the public ip address of our computer and they would add it to the white list.
Since our firewalls and routers translate internal private ip addresses to a different set of public external ip addresses, knowing the machine’s internal ip address isn’t much help. Requests to outside machines will see requests from our machine as a different, external ip address. We needed to know what those external machines would see.
Our hosting engineer was able to look up what the machine’s external ip address would be mapped to, but since we were having the ip address registered in a partner’s system, I wanted to make 100% sure it was correct. I wanted an answer from the horse’s mouth. It’s not that I didn’t trust the engineer; I just wanted to see it for myself…. Well, okay, I admit it. I can be a bit of a control freak at times.
On a Windows machine, checking a computer’s ip address is pretty straightforward. Open a web browser, point it at www.whatismyipaddress.com, and look at what ip address it shows you.
On a linux machine, it’s not so simple. There are none of these fancy icons or windows. It’s just an SSH session in a terminal window. Opening a web browser is not an option. So how to check using nothing but the command line?
My friends at Akamai have set up a site that is useful for this situation called whatismyip.akamai.com. It’s similar to public services such as www.whatismyipaddress.com, but it is completely stripped down. All it does is send back your ip address. No ads, no explanatory messages, no headers, just the ip address.
You can then combine this with wget in quiet mode to fetch the public ip address and display it on the command line as follows:
$ wget -q -O - http://whatismyip.akamai.com
There isn’t even a line break in the output file, so you can see how it would be easy to incorporate this into shell scripts and other utilities. I would guess that this is why Akamai set up the site in the first place. Very kind of them to allow the rest of us to use it.