Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to Find Linux Server Geographic Location in Terminal?
When you need to find the geographic location of a Linux server for security purposes, cyber-crime investigations, or compliance requirements, you can track its location using its IP address and third-party geolocation services. This process involves getting the server's IP address and mapping it to geographic coordinates using web APIs.
Step 1 ? Install Required Tools
First, install curl and jq packages. The curl tool makes HTTP requests to geolocation APIs, while jq processes the JSON responses ?
sudo apt-get install curl jq
The output shows the installation progress ?
$ sudo apt-get install curl jq Reading package lists... Done Building dependency tree Reading state information... Done curl is already the newest version (7.47.0-1ubuntu2.14). The following NEW packages will be installed: jq libonig2 ... Setting up libonig2:amd64 (5.9.6-1ubuntu0.1) ... Setting up jq (1.5+dfsg-1ubuntu0.1) ... Processing triggers for libc-bin (2.23-0ubuntu11) .
Step 2 ? Find the Server's IP Address
Use nslookup to find the server's IP address if you know the domain name. Let's use oracle.com as an example ?
nslookup www.oracle.com
The command returns the IP address associated with the domain ?
Server: 127.0.1.1 Address: 127.0.1.1#53 Non-authoritative answer: www.oracle.com canonical name = ds-www.oracle.com.edgekey.net. ds-www.oracle.com.edgekey.net canonical name = e870.dscx.akamaiedge.net. Name: e870.dscx.akamaiedge.net Address: 104.80.62.56
Step 3 ? Get Geographic Information
Use the ipinfo.io service to get detailed location information about the IP address. This returns JSON data with hostname, city, state, country, and coordinates ?
curl https://ipinfo.io/104.80.62.56
The API returns comprehensive location data ?
{
"ip": "104.80.62.56",
"hostname": "a104-80-62-56.deploy.static.akamaitechnologies.com",
"city": "New York City",
"region": "New York",
"country": "US",
"loc": "40.7143,-74.0060",
"org": "AS20940 Akamai International B.V.",
"postal": "10004",
"timezone": "America/New_York",
"readme": "https://ipinfo.io/missingauth"
}
Finding Precise Latitude and Longitude
For more detailed coordinates, use the ipvigilante.com service combined with jq to extract specific fields from the JSON response ?
curl -s https://ipvigilante.com/104.80.62.56 | jq '.data.latitude, .data.longitude, .data.city_name, .data.country_name'
This extracts the latitude, longitude, city, and country ?
"42.36260" "-71.08430" "Cambridge" "United States"
Comparison of Geolocation Services
| Service | Data Format | Best For |
|---|---|---|
| ipinfo.io | JSON | General location info with timezone |
| ipvigilante.com | JSON | Precise coordinates |
Conclusion
You can easily track server geographic locations using nslookup to find IP addresses and geolocation APIs like ipinfo.io or ipvigilante.com. Use jq to parse JSON responses for specific location details like coordinates and city information.
