How To Find The Geolocation Of An IP Address From Commandline
A while ago, we wrote an article that described how to find out your geolocation from commandline using whereami utility. Today, we will see how to find the geolocation of an IP address. Of course, you can see this details from a web browser. But, it is lot easier to find it from commandline. geoiplookup is a command line utility that can be used to find the Country that an IP address or hostname originates from. It uses the GeoIP library and database to collect the details of an IP address.
This brief guide describes how to install and use geoiplookup utility to find the location of an IP address in Unix-like operating systems.
Find The Geolocation Of An IP Address Using Geoiplookup From Commandline
Geoiplookup is available in the default repositories of most Linux operating systems.
To install it on Arch Linux and its derivatives, run:
sudo pacman -S geoip
On Debian, Ubuntu, Linux Mint:
sudo apt-get install geoip-bin
On RHEL, CentOS, Fedora, Scientific Linux:
sudo yum install geoip
sudo zypper install geoip
Once installed, you can find out any IP address’s geolocation like below.
The above command will find and display the Country that 220.127.116.11 originates from, in the following format:
GeoIP Country Edition: NL, Netherlands
Download and update Geoip databases
Generally, the default location of Geoip databases is /usr/share/GeoIP/. The databases might be bit outdated. You can download the latest databases that contains the updated geolocation details, from Maxmind. It is the website that offers the geolocation of an IP address.
Go to geoip default database folder:
Download the latest databases:
Now, run the geoiplookup command to find most up-to-date geolocation details of an IP address.
GeoIP Country Edition: US, United States
As you see in the above output, it displays only the country location. Geoiplookup can even display more details such as the state, city, zip code, latitude and longitude etc. To do so, you need to download the city databases from Maxmind like below. Make sure you’re downloading it in /user/share/GeoIP/ location.
Now, run the below command to get more details of an IP address’s geolocation.
geoiplookup -f /usr/share/GeoIP/GeoLiteCity.dat 18.104.22.168
Sample output would be:
GeoIP City Edition, Rev 1: US, CA, California, Mountain View, 94043, 37.419201, -122.057404, 807, 650
If you have saved the database files in a custom location other than the default location, you can use ‘-d’ parameter to specify the path. Say for example, if you have saved the database files in /home/sk/geoip/, the command to find the geolocation of an IP address would be:
geoiplookup -d /home/sk/geoip/ 22.214.171.124
For more details, see man pages.
Hope this helps. if you find this guide useful, please share it on your social networks and support us.
Thanks for stopping by!
Help us to help you:
- Subscribe to our Email Newsletter : Sign Up Now
- Support OSTechNix : Donate Via PayPal
- Download free E-Books and Videos : OSTechNix on TradePub
- Connect with us: Facebook | Twitter | Google Plus | LinkedIn | RSS feeds
Have a Good day!!