Services location in linux

How to List All Running Services in Linux

Linux-based operating systems, like all other operating systems, have processes and services that run while the machine is on. These range from various operating system services, to the command line, to different services/daemons designed to maintain the system and keep it running smoothly. Most services are vital to a process’ normal operation, ranging from helper services to special services designed to handle input, improve performance, offload resources, etc. Processes are also the backbone of a computer’s core functionality, making it important to have the resources for them all.

However, it may occur that a service can run without your knowledge, use up system resources, and even make your system vulnerable if security measures have not been taken into account. Because of possible cases like these, it’s good to know how to check and deal with such cases, as well as have the ability to monitor what processes and services are running on your machine at any moment.

In this tutorial, we will go through several methods of listing/showing all running services and processes on a Linux-based server or machine, as well as go through some useful commands that will help you find and manage these processes and services.

The ‘service’ command line tool

The ‘service’ command comes pre-installed with almost every Linux distribution out there. While its main purpose is to start and stop scripts and create processes, ‘service’ can also be used to see what services are running or stopped at any given moment. Using a simple command, we are given a complete list of services:

When you run this, an output similar to this will appear:

As you can see, a list of services is given as output, with a symbol to the left of the service’s name. A ‘+’ symbol means the service is running, a ‘-‘ means that it is stopped, and a ‘?’ means that the status is not currently known. When this is used in combination with a search tool such as ‘grep’, finding specific services that are running is very easy to do. You can then check the status on a process-by-process basis by entering the status command for a specific process:

This will then output a set of information pertaining to that specific service, including the location of the process, whether or not the service is running, and even the last few lines of the log file from the service.

Short for ‘process status’, PS is a pre-installed utility designed to display information and details about processes. It is a simple, fast tool designed to give quick results with no fuss. With one simple command, we can list a well-detailed list of currently running processes:

You can use this in conjunction with the ‘less’ command to further improve readability. When running this command, we are given details for each process currently running. You can also use the ‘grep’ command to narrow down the results to a specific process name, process ID, and so on.

The ‘top’ command line tool

‘top’ is a built-in tool designed to give an overview of all processes and services currently running on your machine. It is included on both Debian-based and RedHat-based distributions and offers a variety of features to help you figure out what’s happening on your server. You can start ‘top’ by simply writing top on the command line. This is what it should look like:

Читайте также:  Web управление для windows

It can look a bit cluttered, but a lot of this information is very useful. For example, we can see how long the system has been running, the average load, how many users are logged in, how many processes (tasks) are running, sleeping, etc. as well as info on the amount of memory we have in total and available on the server. Top goes into even greater detail, down to a process-specific level. Each column displays a specific value that correlates with the process that is running. We can see who owns the process, how much memory it’s utilizing, how much of the CPU is being utilized, the command name, and the process ID, which is unique to that process and helps us identify it in case there’s more than one of the same process. Using all of this information, we can see exactly what each process is doing, and how many resources each process uses up, all in real-time.

Htop is a lot like ‘top’ in terms of its core features and functionality. It is not usually included in a default operating system install, however, it is available for most if not all Linux distributions through its pre-installed software repositories. Like top, htop allows the user to view detailed information about each process, as well as keep tabs on the system itself. However, htop allows for much finer control over the information displayed to you, as well as offering a suite of utilities that can be applied to processes.

For example, through htop, you can adjust the niceness (the priority) of a process, kill it with varying levels of force, and so on. There’s also sorting, which makes it easier to see only the information that is important to you. Selecting a process is possible using the space bar, making it easier to follow and keep track of a specific process (or processes, since you can select more than one at a time). And with a search function, it’s even easier to check and pay attention to specific processes. Htop even has a bar chart that represents the various system resources, allowing you to easily see how much CPU or RAM is allocated.

Here’s an example of what htop looks like:

With the bars at the top, it’s easy to know how your system is doing with just a glance, along with customizable detailed info available just below them.

By using any of these tools, you can easily find the exact information that you need regarding your services and processes.

PS. If you liked this post on how to see which services are running in Linux, please share it with your friends through social media by using the share shortcuts, or simply leave a comment below. Thanks.

Источник

How to List All Running Services Under Systemd in Linux

A Linux systems provide a variety of system services (such as process management, login, syslog, cron, etc.) and network services (such as remote login, e-mail, printers, web hosting, data storage, file transfer, domain name resolution (using DNS), dynamic IP address assignment (using DHCP), and much more).

Technically, a service is a process or group of processes (commonly known as daemons) running continuously in the background, waiting for requests to come in (especially from clients).

Linux supports different ways to manage (start, stop, restart, enable auto-start at system boot, etc.) services, typically through a process or service manager. Most if not all modern Linux distributions now use the same process manager: systemd.

Systemd is a system and service manager for Linux; a drop-in replacement for the init process, which is compatible with SysV and LSB init scripts and the systemctl command is the primary tool to manage systemd.

In this guide, we will demonstrate how to list all running services under systemd in Linux.

Listing Running Services Under SystemD in Linux

When you run the systemctl command without any arguments, it will display a list of all loaded systemd units (read the systemd documentation for more information about systemd units) including services, showing their status (whether active or not).

Читайте также:  Мигает экран при включении windows

To list all loaded services on your system (whether active; running, exited or failed, use the list-units subcommand and —type switch with a value of service.

List All Services Under Systemd

And to list all loaded but active services, both running and those that have exited, you can add the —state option with a value of active, as follows.

List All Active Running Services in Systemd

But to get a quick glance of all running services (i.e all loaded and actively running services), run the following command.

List Running Services in Systemd

If you frequently use the previous command, you can create an alias command in your

/.bashrc file as shown, to easily invoke it.

Then add the following line under the list of aliases as shown in the screenshot.

Create a Alias for Long Command

Save the changes in the file and close it. And from now onwards, use the “running_services” command to view a list of all loaded, actively running services on your server.

View All Running Services

Besides, an important aspect of services is the port they use. To determine the port a daemon process is listening on, you can use the netstat or ss tools as shown.

Where the flag -l means print all listening sockets, -t displays all TCP connections, -u shows all UDP connections, -n means print numeric port numbers (instead of application names) and -p means show application name.

The fifth column shows the socket: Local Address:Port. In this case, the process zabbix_agentd is listening on port 10050.

Determine Process Port

Also, if your server has a firewall service running, which controls how to block or allow traffic to or from selected services or ports, you can list services or ports that have been opened in the firewall, using the firewall-cmd or ufw command (depending on the Linux distributions you are using) as shown.

List Open Services and Ports on Firewall

That’s all for now! In this guide, we demonstrated how to view running services under systemd in Linux. We also covered how to check the port a service is listening on and how to view services or ports opened in the system firewall. Do you have any additions to make or questions? If yes, reach us using the comment form below.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

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.

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.

Читайте также:  Haxm installer windows download

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.

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.

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.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

8 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 .

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:

I’ll be adding more parsers to make life easier for cli jockeys!

Thanks for sharing, we are grateful.

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.

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

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

You can also find IP by using:

and if GeoIP is installed:

Gives you the country name and info about your ISP.

If you specify location of GeoLiteCity.dat file:

You get the rest (city and coordinates).

Thanks for sharing, we are grateful.

Got something to say? Join the discussion. Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Источник

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