Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to List Services in Linux
#1


    How to List Services in Linux

   

How to List Services in Linux


   

Let's consider a potential scenario. While running your Linux system, you might find that you can no longer access localhost. This could be due to the HTTP service being disabled, causing the problem.

   

To troubleshoot such issues and more, it's important to know how to list all services in Linux.

   

Fortunately, CentOS and Ubuntu, two of the most popular operating systems in their domains, use systemd. This means that the commands we're going to present are compatible with both systems.


   

First, we need to connect to our server using SSH. If you're having trouble, you can check out our PuTTY tutorial.

   

Once inside, we need to be the root user to list services in Linux:

   
su
   

Now we can list all services in Linux using the following command:

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

When this command is executed, we will see all the services on the system. Some of these services will have a defined status. Let's understand what these statuses mean:

   
           
  • Enabled services are currently running and usually have no issues.
  •        
  • Disabled services are not active but can be activated at any time without problems.
  •        
  • Masked services won't run unless their properties are changed.
  •        
  • Static services are used only when another service or unit requires them.
  •        
  • Services generated through SysV or LSB initscripts with systemd generator.
  •    
   

If you want to know only the active services, you can use the following command along with grep:

   
sudo systemctl | grep running

   

Managing Linux Services


   

Now let's learn how to manage a specific service. Keep in mind that each service represents software that works differently. In this tutorial, we'll show you how to start, check the status of, and stop services – the basic controls.

   

To start a service on Linux, use the following command:

   
sudo systemctl start [service_name]
   

If the service is correctly configured, it will start. To stop it, use this command:

   
sudo systemctl stop [service_name]
   

To check the status of a service, you can use:

   
sudo systemctl status [service_name]
   

You can also configure a service to run during the operating system's startup:

   
sudo systemctl enable [service_name]
   

Or remove it from the startup:

   
sudo systemctl disable [service_name]
   

Finally, you can verify which port a service is using by using netstat.

   

To install it on Ubuntu, run:

   
sudo apt install netstat-nat
   

If you're using CentOS 7:

   
yum install net-tools
   

Then, run the following command:

   
sudo netstat -plnt
   

The output will provide all the necessary network information.


   

   

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)