Updated: 3 November 2026 · Applies to: ipinfo.io's public geolocation API

To find a Linux server's geographic location from the terminal, query a free IP geolocation API with curl. ipinfo.io returns your server's public IP address plus its city, region and country in a single request, so no second lookup is needed.

Install curl and jq

curl makes the API request, and jq reads the specific fields out of its JSON reply.

On Debian or Ubuntu:

apt install -y curl jq

On AlmaLinux, Rocky Linux or RHEL:

dnf install -y curl jq

Terminal output of installing curl and jq

Find the server's public IP address

Run:

curl https://ipinfo.io/ip

Terminal output of curl https://ipinfo.io/ip, showing just the public IP address

This prints just the IP address, nothing else.

Get the city, region and country

Request the full record instead, which includes location data along with the IP address:

curl https://ipinfo.io/json

This returns the server's IP address, hostname, city, region, country code, coordinates, network and time zone as JSON. To pull out just the location fields with jq:

curl -s https://ipinfo.io/json | jq -r '"City: " + .city, "Region: " + .region, "Country: " + .country, "Coordinates: " + .loc'

The coordinates field is a single string of latitude and longitude separated by a comma.

Save it as a script

To avoid typing the full command every time, save it as a small script. Create the file:

vim getipgeoloc.sh

Paste in the following line:

curl -s https://ipinfo.io/json | jq -r '"City: " + .city, "Region: " + .region, "Country: " + .country, "Coordinates: " + .loc'

Save the file, then make it executable:

chmod +x getipgeoloc.sh

Run it whenever you need the server's location:

./getipgeoloc.sh

A note on rate limits

ipinfo.io answers a reasonable number of requests a day without any signup. If you need to run this check often, for example from a monitoring script on several servers, create a free account on ipinfo.io and add a token to the request, which raises the daily limit.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $135 a month.

Was this answer helpful?

Still stuck? Open a ticket