Sometimes, you might need to find out the geographical location of a Linux server, more so a cloud server. Such information may include its IP address and Physical location in terms of Country, City, and coordinates ( Longitudes and Latitudes ). There are different ways of going about this and in this tutorial we will examine how to find your server’s Geographic location.
As you begin, be sure that curl is installed. We shall use it to make API requests later on in this guide. You can confirm its presence or installation by invoking
$ curl --version
Find the Public IP address of the server
If you have the public IP address of the Linux server, that’s fine. However, if you are currently logged in and would want to verify the server’s public IP, you can do so by running the following curl command.
$ curl https://ipinfo.io/ip
Additionally, you can also invoke the curl command followed by the ifconfig.me tool that is used for displaying the public IP address on Linux systems.
$ curl ifconfig.me
Find the Geographical details of the server
With the IP address in hand, you can now proceed to extract the precise Geographical details by sending API requests to ipinfo.io as shown. The ip-address is the public IP of the server.
$ curl https://ipinfo.io/ip-address
The command yields a wealth of information in JSON format which includes the city, country, region, geolocation in terms of latitude and longitude, and the timezone where the server is situated.
If you just want to get the Country information alone, you can use the geoip lookup tool. This is available in repositories for major Linux distributions. You can install it as follows.
$ sudo yum install geoip
On Ubuntu / Linux Mint
$ sudo apt install geoip-bin
On Arch / Manjaro
$ sudo pacman -S geoip
On SUSE Linux
$ sudo zypper install geoip
Once installed, you can run it as provided to obtain the country where your server is located.
$ geoiplookup IP-address
These are simple and handy ways that you can use to extract the geographical information of a Linux server on the command line.
Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.