Linux Tutorials
About Lesson

Systemd service management:

Linux service is an application (or set of applications) that runs in the background waiting to be used, or carrying out essential tasks. … This is the most common Linux init system.

On the other hand, in systems like Unix or Linux, the services are also known as daemons. Sometimes the name of these services or daemons ends with the letter d. For example, sshd is the name of the service that handles SSH.

Listing services
systemctl To list running services
systemctl –failed To list failed services

Managing Targets (Similar to Runlevels in SysV)

systemctl get-default To find the default target for your system
systemctl set-default <target-name> To set the default target for your system

Managing services at runtime
systemctl start [service-name] To start a service
systemctl stop [service-name] To stop a service
systemctl restart [service-name] To restart a service
systemctl reload [service-name] To request service to reload its configuration
systemctl status [service-name] To show current status of a service

Managing autostart of services
systemctl is-enabled [service-name] To show whether a service is enabled on system boot
systemctl is-active [service-name] To show whether a service is currently active(running)
systemctl enable [service-name] To enable a service on system boot
systemctl disable [service-name] To disable a service on system boot

Masking services
systemctl mask [service-name] To mask a service (Makes it hard to start a service by mistake)
systemctl unmask [service-name] To unmask a service

Restarting systemd
systemctl daemon-reload

 

How to List Services in Linux

Let’s look at a potential scenario. While running your Linux system, you can no longer access localhost. Chances are that the HTTP service was disabled, and causing the problem.

To troubleshoot issues like this one and many others, it’s good to know how to list all services in Linux.

Fortunately, CentOS and Ubuntu – two of the most popular operating systems in their areas – share systemd. That means that the commands we are going to present are compatible with both systems.

First, we have to connect to our server using SSH. If you’re having trouble, check out our PuTTY tutorial.

Once inside, we need to be the root user to list service in Linux.

su

Now we can list all services in Linux. To do it, run the command:

sudo systemctl list-unit-files --type service --all

When the command is run, we will see all the services that are on the system. However, we will also see that some have a defined status. Let’s learn what all these mean.

  • Enabled services are currently running. They usually have no problems.
  • Disabled services are not active but can be activated at any time without a problem.
  • Masked services won’t run unless we take that property away from them.
  • Static services will only be used in case another service or unit needs it.
  • Finally, there are services generated through a SysV or LSB initscript with systemd generator.

In case we want to know only the services that are active, we have to use a command together with grep, like so:

sudo systemctl | grep running

Managing Linux Services

Now it is time to learn how to manage a specific service. Note that each service represents software that works differently. In this tutorial, we will only show how to start, check the status of and stop services – the basic controls

To start a service on Linux, we need to run the following command:

sudo systemctl start [service_name]

If the service is correctly configured, it will start. Now, if we want to stop it, we will use the following command:

sudo systemctl stop [service_name]

Meanwhile, to check the status of a service we can use:

sudo systemctl status [service_name]

It is also possible to have a service run while the operating system is being loaded:

sudo systemctl enable [service_name]

Or remove it from the initial load:

sudo systemctl disable [service_name]

Finally, it is possible to verify which port is being used by a service. For this, we will use netstat.

To install it on Ubuntu, we just run:

sudo apt install netstat-nat

If we are using CentOS 7:

yum install net-tools

Then, we run the following command:

sudo netstat -plnt

The output will give us all the required network information.

Let’s Join our Hacking Team

We Are Indian We Are Great

Hope this article helpful for you. Thank You

Indian Cyber Army | Make IT Secure

Enjoy…Stay Happy…Stay Secure…

Hope this article helpful for you. Thank You


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

Hackonology is the fastest growing and most trusted community site where you can find lots of courses, articles about Technology/Hacking/Cracking. Millions of people visit Hackonology! to search or browse the thousands of published articles available FREELY to all.

Let's be a part of Hacker's Community! Join our Hacking Team

We Are Indian We Are Great