Sometimes, you might want to retrieve the geographical location of a Linux server due to a wide range of reasons. These include conducting cybercrime forensics or simply out of curiosity.
There are a couple of tools and APIs that you can use to get geographical information about Linux servers such as the IP address, country, and other details. In this guide, we will explore how to find the geolocation of the IP address of a Linux system.
Find Geolocation Using IPinfo
IPInfo is an IP address geolocation lookup that provides a wealth of information about the server’s current geographical information that includes public IP address, City, region country, and timezone.
Find Linux Server Geographic Location
A few prerequisites are required before using the IPInfo lookup tool. You need to install curl and jq command line tools to process data in JSON format from geolocation APIs.
$ sudo apt install jq curl [On Debian, Ubuntu and Mint] $ sudo yum install jq curl [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux] $ sudo emerge -a jq curl [On Gentoo Linux] $ sudo apk add jq curl [On Alpine Linux] $ sudo pacman -S jq curl [On Arch Linux] $ sudo zypper install jq curl [On OpenSUSE]
Once installed, you can now query your server’s geolocation details by making a curl request to the geolocation API as shown.
$ curl https://ipinfo.io/json
You will get the following output in JSON format.
Find IP Address Geographic Location Using GeoIP Tool
To retrieve information about the country in which the Linux server is hosted, use the GeoIP lookup tool which can be executed on the command line.
But first, you need to install the tool on your Linux system.
$ sudo apt install geoip-bin [On Debian, Ubuntu and Mint] $ sudo yum install geoip [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux] $ sudo emerge -a geoip [On Gentoo Linux] $ sudo apk add geoip [On Alpine Linux] $ sudo pacman -S geoip [On Arch Linux] $ sudo zypper install geoip [On OpenSUSE]
Once installed, you can obtain the country information where the server is hosted as shown.
$ geoiplookup ip-address
Find Linux Server IP Address
The IPInfo tool can also return the public IP address only of the server using the following syntax.
$ curl https://ipinfo.io/ip
Additionally, using the cURL command, you can retrieve the public IP address of your Linux server as shown.
$ curl ifconfig.co $ curl ifconfig.me $ curl icanhazip.com
Conclusion
In this article, we have covered some of the ways that you can use to find the geolocation of an IP address and additional information about a Linux server with regard to its location. As always, we cherish your feedback.