How to find geographic server location using terminal in Debian 10

Each server has an open IP address, which is assigned to the server directly through the router. This public IP address can be used to track the geolocation of a server that reports information, including continent, country, and even estimated latitude and longitude of the server.

In many cases, you need to choose the geographical location of a remote Linux computer based on its IP address. You may know how to find the server geolocation from a web browser, but today we will see how to find it through the Terminal application in the Debian OS. In this article, we will explain how to find the public IP address of the system, and then use this IP address to retrieve its geographic location through two public APIs provided by ipinfo.io and ipvigilante.com.

Location information can be used in many ways. Some of its uses are listed below:

  • Information Security
  • Digital advertising
  • Content personalization
  • Geomarketing
  • Law enforcement

We have completed the commands and procedures mentioned in this article on Debian 10.

Show geographic location of IP address on terminal

To get the geographic location of your server, you need the Curl loader and the JQ command-line tool. This tool will allow you to receive and process the necessary data from the geolocation API from the Internet. Follow these steps to install these tools, and then obtain the necessary location information using the public IP address of your computer.

Step 1: Install curl and jq

Launch a terminal on your Debian OS. To do this, go to activity Tab in the upper left corner of the desktop. Then in the search bar enter Terminal, When the terminal icon appears, click on it to launch it.

Switch to the superuser account on your Debian OS using the following command in the terminal, and then enter the required password.

$ su

Then run the following command in Terminal to update the repository index of your system:

$ apt-get update

Curl will be used to make HTTP requests, and jq will be used to process JSON data from the geolocation API. Curl and jq are available in the official Debian repositories, so we can install them using the apt-get command in Terminal.

Run the following command in Terminal to install curl and jq:

$ apt get insntall curl jq

Install curl

System will provide you Y / N The ability to continue or cancel the installation process. To come in Y and then press Enter. Then wait a while until the installation of the above tools is complete.

Step 2: Find the public IP address of the Debian computer / server

To find the geographic location of the server, we need its public IP address. This is the address assigned to your server or router by your ISP. All servers on the Internet are recognized by these IP addresses. To get the public IP address, we will use the API provided by ipinfo.io,

We will have to use the curl command to call the API ipinfo.ioTo do this, open a Terminal and run the following command:

$ curl https://ipinfo.io/ip

Find server IP address

The above output (blurred here for privacy reasons) is the public IP address of the server through which it is connected and recognized in the world of the Internet.

Step 3: Get Geolocation Based on Public IP

Now we have the public IP address of the server, now we will make a request ipvigilante.com’s API for receiving server geolocation data. For this purpose we will use the curl command. She will receive the following information:

  • continent
  • The country
  • State / province
  • town
  • Latitude and longitude

Run the command below in Terminal to get geolocation data from ipvigilante.com’s API using curl:

$ curl https://ipvigilante.com/

Replace with your public IP address.

Get geolocation based on public IP

Alternative IP geolocation providers:

curl http://api.geoiplookup.net/?query=
curl https://json.geoiplookup.io/

Replace with your public IP address.

Use a Bash script to print a geographic location

Each time you need to check the geographic location of your server, you must follow all the steps above. Instead, we can automate this process by creating a bash script. This script will allow you to get the geographic location of your server by running only one command. Follow these steps to create a script.

We can create a script using any text editor. For the current scenario, we use a nano editor, so we type nano then the name of the script (name it whatever you want).

$ nano geolocation.sh

Then copy and paste the following line using the context menu.

$ curl -s https://ipvigilante.com/$(curl -s https://ipinfo.io/ip) | jq '.data.latitude, .data.longitude, .data.city_name, .data.country_name'

Click Ctrl + O save the script and Ctrl + X go out

The script to get the location of the GEO server

Now we will execute the above script, granting it rights to execute. To do this, run the following command in Terminal:

$ chmod +x geo_location.sh

Now we are ready to test the script. Run the following command in Terminal to run the script.

$ ./geo_location.sh

Run geolocation script

From the above conclusions it can be seen that the script accurately printed the latitude, longitude, city and server name in the Terminal.

That’s all! We learned how to find the geographic location of a server using a Debian terminal. The geographical location of the IP provides useful information consisting of the name of the country, city, latitude and longitude. You can use this information can be used in several ways, as described above in the article.

How to find geographic server location using terminal in Debian 10

Sidebar