List All Running Services in Linux: [Using 4 Tools]

 

List All Running Services in Linux: [Using 4 Tools]

In this tutorial, we will learn about how to list all running services in Linux using 4 tools. Understanding services in Linux is a fundamental skill for system administrators and developers working with Linux-based systems. There are variety of services available in Linux broadly divided as system services (process management, login, syslog, cron etc.) and network services (remote login, web hosting, file transfer etc.) We will talk more about services and various network tools to view the running services in Linux in the upcoming sections of this tutorial. So let’s get started.

 

Service in Linux Overview

‘Service’ in Linux refers to programs or processes that run in the background, providing specific functions or capabilities to the operating system or to users. Services handles multiple tasks such as networking, file sharing, printing and more. In modern Linux, servcies are managed my Systemd manager that handlles the initialization of the system along with service managment.

With Systemd, services are controlled using the systemctl command. For example, to start a service, you will use command below:

sudo systemctl start <service-name>

To stop a service, you will use the command below:

sudo systemctl stop <service-name>

 

List All Running Services in Linux: [Using 4 Tools]

Also read: Install Maven on Linux [Step by Step Configuration Guide]

Tool-1: Using Systemctl

In Linux, ‘systemctl’ is a tool which is primarily used to manage system services, examine system state and control the state of the Linux system’s init system(System V init or systemd). It is a standard interface for controlling the init system and services.  It is used across various Linux distributions specially those using systemd as their init system.

We use systemctl command to list down all running services in Linux as shown below. As you observe the output of systemctl command, it shows that sshd, rsyslog, rpcbind and many other services are currently active and in running state.

# systemctl
UNIT             LOAD   ACTIVE SUB       DESCRIPTION
rsyslog.service  loaded active running   System Logging Service
..............
rpcbind.service  loaded active running   RPC bind service
..............
sshd.service     loaded active running   OpenSSH server daemon

 

Tool-2: Using netstat

In Linux, ‘netstat’ is a command-line network  utility tool which is used to get information about network connections, routing tables, interface statistics and multicast memberships. netstat tool is used to inspect and troubleshoot network-related issues. Below command is used to view all active network connections, both incoming and outgoing. Here we use multiple flags along with the command netstat. Each flag has below meaning:

-t:  TCP connections.
-u: UDP connections.
-l: Listening ports.
-n: Show numerical addresses instead of resolving hostnames.

# netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address     Foreign Address State    PID/Program name
tcp    0      0     0.0.0.0:111       0.0.0.0:*        LISTEN  76132/rpcbind
tcp    0      0     100.73.52.149:22  0.0.0.0:*        LISTEN  400735/sshd
tcp    0      0     192.100.1.41:22   0.0.0.0:*        LISTEN  400735/sshd
tcp    0      0     127.0.0.1:22      0.0.0.0:*        LISTEN  400735/sshd

 

Tool-3: Using nmap

In Linux, nmap (Network Mapper) is a powerful open-source network scanning tool which is used to discover hosts and services in a network, thus creating a ‘map’ of networks. Nmap sends packets to hosts within a network and analyzes their responses to perform various tasks such as network discovery, service version detection and vulnerability scanning. We are executing nmap command for localhost which scans all open ports on the localhost.

# nmap localhost
Starting Nmap 6.40 ( http://nmap.org ) at 2023-09-20 20:39 IST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000017s latency).
Other addresses for localhost (not scanned): 127.0.0.1
Not shown: 993 closed ports
PORT    STATE  SERVICE
22/tcp  open   ssh
111/tcp open   rpcbind

 

Tool-4: Using lsof

In Linux, ‘lsof’ (List Open Files) is a command-line utility which provides detailed information about the files that are currently opened by processes. These files can include regular files, directories, network sockets, block special files, character special files and even devices. Below command shows all network-related information. It displays network connections, open ports and other network-related information.

# lsof -i
sshd 2384848 root 3u IPv4 759952406 0t0 TCP karan:ssh->10.143.119.218:64151 (ESTABLISHED)
sshd 4167590 root 3u IPv4 740026059 0t0 TCP *:ssh (LISTEN)
sshd 4167590 root 4u IPv6 740026061 0t0 TCP *:ssh (LISTEN)

 

Summary

There are many other utilities available in Linux which helps to do certain operations on services such as ps, top, pgrep, service etc. You can explore each of these commands to understand how these helps to analyze, create and troubleshoot service related issues in Linux.

Leave a Comment