Find linux server information

How to Find Linux Server Geographic Location in Terminal

In this article, we will show you how to find the IP address geographic location of a remote Linux system using open APIs and a simple bash script from the command line.

On the internet, each server has a public-facing IP address, which is assigned directly to the server or via a router that sends network traffic to that server.

IP addresses provide an easy way to track the location of the server in the world by using two useful APIs provided by ipinfo.io and ipvigilante.com to get the city, state, and country connected with a server.

Install Curl and jq

To get the IP address geographic location of the server, we need to install curl command line downloader and jq command-line tool to process the JSON data from the geolocation APIs.

$ sudo apt install curl jq #Ubuntu/Debian $ sudo yum install curl jq #CentOS/RHEL $ sudo dnf install curl jq #Fedora 22+ $ sudo zypper install curl jq #openSUSE

Install Curl and JQ in Linux

Find the Server’s Public IP Address

To get the server’s public IP address, use the following curl command to make an API request to ipinfo.io in your terminal as shown.

Get Linux Server IP Address

Get IP Location Data From The API

Once you have got the server public IP address, you can now make a request to ipvigilante.com‘s API to fetch the geolocation data using the following command. Make sure to replace with the server’s public IP.

Get Linux IP Geo Location

This is the data we get from the above command.

Server Location Details

Automate API Call using Bash Script

Now to automate the API process, we will create a script called getipgeoloc.sh (you can name it anything you want) using any of your favorite command line editors.

Then copy and paste the following long command in it.

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

Save the file and make the script executable with the following command.

Finally, run the script to get your Linux IP geographical location as shown in the following screenshot.

Find Linux Server Geolocation

The above script shows the city and country name along with the approximate latitude and longitude coordinates.

Alternatively, you can also run the above command without saving it in a script as shown.

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

Get Linux Server Location Details

You might also like to read these following related articles:

That’s it for now! In this short article, we have shown how to get your Linux IP geographic location from the terminal using the curl and jq commands. Share your thoughts with us or ask any questions via the feedback form below.

Читайте также:  Linux выполнение нескольких команд

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Parted Command in Linux

TLDR Man Pages for Linux Commands

apt-get Command Examples

Ubuntu apt-cache Commands

apt Command Examples

Funny Linux Commands

9 thoughts on “How to Find Linux Server Geographic Location in Terminal”

gip -g prints the geo location for the IP address. The tool is available at GitHub: https://github.com/softhub-software-development/gip . Reply

I created a command-line tool called jc that JSONifies the output of many common Linux CLI tools for piping into jq. No need to parse with sed/awk/grep/tr/cut/etc. 🙂 For example:

$ ifconfig | jc --ifconfig | jq .

https://github.com/kellyjonbrazil/jc I’ll be adding more parsers to make life easier for cli jockeys! Reply

There are many geoip lookup services. My issue with ipinfo.io is that they don’t appear to do IIPv6. By way of contrast, ipgeolocation.io has a comparable API and *will* do IPv4 and IPv6 addresses. They do require that you get an API key, but they have a development pricing level that’s free.

[email protected]:/home/jeffs $ curl -4 -s «https://api.ipgeolocation.io/ipgeo?apiKey=$» | jq «.ip» | sed -e s/\»//g
97.126.67.233

[email protected]:/home/jeffs $ curl -6 -s «https://api.ipgeolocation.io/ipgeo?apiKey=$» | jq «.ip» | sed -e s/\»//g
2602:61:7e43:e900:58fd:e794:22b1:e919

Likewise, I can get the information about somebody else’s IPv4 or IPv6 address:

[email protected]:/home/jeffs $ curl -4 -s «https://api.ipgeolocation.io/ipgeo?apiKey=$&ip=208.97.189.29» | jq «.latitude,.longitude» | awk -F»: » ‘< print substr($1,2,length($1)-2)>‘
33.91670
-117.90000

[email protected]:/home/jeffs $ curl -6 -s «https://api.ipgeolocation.io/ipgeo?apiKey=$&ip=208.97.189.29» | jq «.latitude,.longitude» | awk -F»: » ‘< print substr($1,2,length($1)-2)>‘
33.91670
-117.90000

I am filtering the outputs through sed to get rid of the ” characters. Bottom line is that there are many IP geolocation services. You should try several different ones, see what API you like best. Everything else in this article is a little bash-foo. Reply

@Jeff Many thanks for sharing this useful information as well as your thoughts about this topic, with us. Reply

Hi Jeff, You can also pass the -r option to jq to get rid of the quotation marks. No need for sed! 🙂 Kelly Reply

# geoiplookup -f /usr/share/GeoIP/GeoLiteCity.dat

Источник

How to Check Linux Server Geographic Location

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.

Читайте также:  Linux перенаправить на консоль

You will get the following output in JSON format.

Find Linux Server Geolocation

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.

Find IP Address Geo Location

Find Linux Server IP Address

The IPInfo tool can also return the public IP address only of the server using the following syntax.

Find Linux Server IP Address

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.

Источник

Gathering System Information On An Ubuntu Server

Apr 6, 2020
4 minute read

ACLU Office

Photo by Christina @ wocintechchat.com on Unsplash

Have you ever wondered what your computer is doing underneath the surface? Beyond our browsers, chatbots and fancy UIs, our machines are quietly doing a ton of work to support our digital needs.

Today, we’ll investigate our operating system and find out what is going on with its software, hardware and network connections. First, let’s dig into the commands that will help us gather information about the server!

Essential System Commands

Without further ado, here are some commands that you can use to extract system information from the server. (Note: some of these commands can only be executed as root. So make sure you have your privileges configured correctly and Sudo when needed!)

Operating system information

First, the basics. Let’s say you want to find out the version of the kernel that you are using. You can use the uname command for this.

The first command prints out the version, and the second just the release number. You can also check the Linux distribution version with these commands:

lsb_release -a hostnamectl 

Hardware information

lshw stands for “List Hardware”. It is a command-line utility that allows users to gather hardware information of the machine. The command generates detailed reports about various hardware components such as the memory capabilities, CPU stats, cache configuration, and so on.

Disk drive information

For example, to check for disk size and information about storage controllers on the system, you can use:

Читайте также:  Alt linux репозитории сизиф

And to find information about the partitions and controllers of disks, you can use this command. This will give you a more detailed view of the memory system.

Alternatively, you can use fdisk to achieve the same results. This command will list the partition tables of a hard disk.

Mount points

To find out information about mounted file systems, you can use these commands:

The lsblk command lists the block devices of the system, and df reports the filesystem’s disk space usage. Read the man page for each command to learn more!

Memory information

You can use this command to find information about the memory hardware:

And the free command to display the amount of free and used memory in the system.

Processor information

Lastly, the lscpu command can be used to find information about the CPU of the machine:

This will display full details about the processor of the system, including the CPU’s vendor, version and capabilities.

The lshw command can also be used:

Process information

What if you wanted to find out more about specific system processes? For example, how do you find the PID of a process? Its current state? And its memory and processing power usage?

You can use the top command or the htop command to find the current processes on the system. You can also use the pgrep command to search for specific processes using their name. (The command will return the PIDs of all the matching processes. You can use the -l option to display the names of the matching processes as well.)

top and htop also display detailed process information. Alternatively, after you find out the PID of your target process, you can use the ps command to get more details.

Network information

To figure out the networking details of the server, you can use these few commands.

ifconfig is a useful command for acquiring networking information of the system. If run without arguments, it will display the status of the currently active network interfaces.

The above command shows the local IP address of the machine. Alternatively, you can use the ip command for this. For example, the command below also shows the local IP address:

The route command displays the IP routing table. You can also use ip for the same results.

netstat prints the current network connections, routing tables, interface statistics, and more.

Lastly, the ss command is used to dump socket statistics. It shows similar information as netstat , but can display more TCP and state information than other tools.

Conclusion

Linux systems are full of built-in utilities that will help you discover more information about the machine. And remember, you can always check the man page of each of these commands to find more ways to use them.

If you are a system admin, a hacker, a programmer, or a student, take some time and dig into your operating system! You never know what interesting things you’ll learn. Have fun!

Источник

Оцените статью
Adblock
detector