How to list all running services under Systemd in Linux

Make a fortune with your little hand, give it a thumbs up!

The Linux system provides a variety of system services (such as process management, login, syslog, cron, etc.) and network services (such as remote login, email, printer, virtual host, data storage, file transfer, domain name resolution, etc.) (using DNS), Dynamic IP address assignment (using DHCP, etc.).

Technically, a service is a process or group of processes (often called a daemon) that runs continuously in the background, waiting for requests to come in (especially from clients).

Linux supports different ways to manage (start, stop, restart, enable autostart on system boot, etc.) services, usually through process or service managers. Most (if not all) modern Linux distributions now use the same process manager: systemd.

Systemd is a system and service manager for Linux; a replacement for the init process, compatible with SysV and LSB init scripts, and the systemctl command is the main tool for managing systemd.

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

List 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 on systemd units), including services, showing their status (whether active or not ).

systemctl 
alt

To list all loaded services on the system (whether active, running, exiting, or failed), use the list-units subcommand with the --type switch with a service value.

# systemctl list-units --type=service
OR
# systemctl --type=service
alt

To list all loaded but active services, both running and exited, you can add the --state option with a value of active as shown below.

# systemctl list-units --type=service --state=active
OR
# systemctl --type=service --state=active
alt

But for a quick overview of all running services (i.e. all loaded and running services), run the following command.

# systemctl list-units --type=service --state=running 
OR
# systemctl --type=service --state=running
alt

If you use the preceding command frequently, you can create an alias command in your ~/.bashrc file as shown in the picture to easily invoke it.

vim ~/.bashrc

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

alias running_services='systemctl list-units  --type=service  --state=running'
alt

Save the changes in the file and close it. From now on, use the "running_services" command to see a list of all loaded, running services on the server.

# running_services #use the Tab completion 
alt

Also, an important aspect of services is the ports they use. To determine the port on which the daemon is listening, you can use the netstat or ss command as shown.

Where the flag -l prints all listening sockets, -t prints all TCP connections, -u prints all UDP connections, -n prints numeric port numbers (instead of application names), and -p prints application names.

# netstat -ltup | grep zabbix_agentd
OR
# ss -ltup | grep zabbix_agentd

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

alt

Also, if your server is running a firewall service that controls how traffic to and from selected services or ports is blocked or allowed, you can use the firewall-cmd or ufw commands to list the services or ports that have been opened in the firewall (depending on the Linux distribution you are using), as shown.

# firewall-cmd --list-services   [FirewallD]
# firewall-cmd --list-ports

$ sudo ufw status     [UFW Firewall]
alt

That's it for now! In this guide, we demonstrated how to view running services under systemd in Linux. We also covered how to check what port services are listening on and how to see what services or ports are open in your system's firewall.

Reference

[1]

Source: https://www.tecmint.com/list-all-running-services-under-systemd-in-linux/

This article is published by mdnice multi-platform

Guess you like

Origin blog.csdn.net/swindler_ice/article/details/131276644