opened image

Services on Linux servers and their administration using Systemd

Linux — is an open-source operating system known for its flexibility, stability, and extensive set of tools for managing processes and services. One such tool is Systemd, which has become the standard for managing system services in most modern Linux distributions. One of the main advantages of Systemd is its ability to efficiently manage running services and system resources.

In this article, we will take a detailed look at how to use Systemd to display all running services, manage them, and monitor the ports used by these services. We will also discuss how to use Systemd for security monitoring through the firewall.

 

What are service management systems in Linux?

 

In Linux, service management is a key aspect of administration. It is important to be able to quickly obtain information about which services are running, which have stopped, or which are disabled. This is necessary for monitoring system performance and troubleshooting if issues arise.

Previously, service administration was done using init — the traditional initialization process responsible for starting services at system boot. However, with the introduction of Systemd, management has become more flexible and powerful. Systemd replaced init and has become the de facto standard in most Linux distributions, such as Ubuntu, CentOS, and Fedora.

 

What is Systemd?

 

Systemd — is a system initialization manager that manages processes and services in Linux. It was created to improve system boot speed and replace the outdated init. Systemd performs several important functions:

  • Initialization of services at system startup.
  • Management of dependencies between services.
  • Monitoring the status of services and processes in the system.
  • Logging (systemd-journald) of all events related to services and processes.

One of the main advantages of Systemd is its compatibility with SysV and support for legacy LSB scripts, allowing for a smooth transition from using init to more modern service management.

Why is it necessary to display running services?

Knowing which services are running on your system is critical for administration. It allows you to:

  • Monitor resource usage: if a service consumes too much memory or CPU power, it may indicate a problem.
  • Troubleshoot: in case of system failures, you can quickly identify which service was the cause of the problem.

Optimize performance: unnecessary services can be disabled or configured to start on demand, reducing the load on the system.

 

 

Displaying all services in Linux through Systemd

 

To display all services that are active in the system, you can use the following command:

systemctl list-units --type=service

This method will output a list of all system units of type "service" loaded into the system. The command shows both active and inactive services. For a simplified output, you can use the shortened command:

systemctl --type=service

 

How to display active services in Systemd

 

Active services are those that are either still running or have completed their work but have not yet been unloaded from memory. To see a list of all active services, you need to execute the following command:

systemctl list-units --type=service --state=active

For output with minimal parameters, you can use an alternative command:

systemctl --type=service --state=active

How to display only running services

Running services are those that are currently executing. To display them, use the following command:

systemctl list-units --type=service --state=running

Alternative command:

systemctl --type=service --state=running

These commands will help system administrators quickly obtain information about which services are currently running.

Key terms in Systemd

  • Unit — is the basic unit in Systemd. Units can be services, devices, mount points, sockets, and other objects managed by the system.
  • Load — status indicating whether the unit is loaded into memory.
  • Active — indicates whether the unit is active (for example, the service is running and operational).
  • SUB — a refined status of the unit that shows its current state, such as "running" or "failed."
  • Description — a brief line that describes the purpose of the unit.

 

Creating an alias for the Systemd command

 

To simplify the invocation of the command to display running services, you can create an alias. This is especially useful if you frequently need to execute the same command.

Add the following alias to the ~/.bashrc file:

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

After adding this alias, update the current session with the command:

 

source ~/.bashrc

Now you can quickly display running services using the command

running_services.

Determining the port on which the service is listening

To find out which port a specific service is using, you can use the following commands:

netstat -ltup | grep <process_name>

Alternative command using ss:

ss -ltup | grep <process_name>

These commands will display all ports on which services are listening for incoming connections, as well as information about the services themselves.

 

Displaying services and ports open in the firewall

 

To control the security of the system, it is important to know which services and ports are allowed in the firewall. Let's look at how to do this using different firewalls.

FirewallD

To display allowed services:

firewall-cmd --list-services

To display open ports:

firewall-cmd --list-ports

UFW

To display the status of UFW and the list of allowed services and ports:

sudo ufw status

These commands will help you determine which ports and services are allowed for external access through the firewall.

 

 

Conclusion

Service management is an important part of administering Linux systems. Systemd provides powerful tools for monitoring and managing services, making it indispensable for modern administrators. With it, you can easily track active services, check their status, and optimize resource usage. Moreover, Systemd allows for the integration of security by monitoring ports and interactions with the firewall, contributing to an increased level of system protection.

 

We also suggest considering other useful articles: