Thursday, 3 October 2019

How to List Services in Linux

LPI Study Materials, LPI Guides, LPI Learning, LPI Tutorial and Materials, LPI Online Exam

In this article, I will show you how to list all running services on Linux. We will also check how to check the status of a service on a systemd system.

Let's learn different commands used to list services on Centos/RHEL 7.x.

Check and Listing linux services (systemd on Centos/RHEL 7.x)


To list  systemd services we will use systemctl command as below

# systemctl list-unit-files

Sample Output

LPI Study Materials, LPI Guides, LPI Learning, LPI Tutorial and Materials, LPI Online Exam

To list active systemd services run

# systemctl | more

Sample Output

LPI Study Materials, LPI Guides, LPI Learning, LPI Tutorial and Materials, LPI Online Exam

Another command you can use is

# systemctl list-units --type service

Sample Output

LPI Study Materials, LPI Guides, LPI Learning, LPI Tutorial and Materials, LPI Online Exam

You can pipe the output to grep to search a more specific service as shown below

# systemctl | grep "apache2"

Output

LPI Study Materials, LPI Guides, LPI Learning, LPI Tutorial and Materials, LPI Online Exam

Listing services using Netstat Command


Nestat command is a tool used for examining active network connections, interface statistics as well as the routing table. It's available in all Linux distributions and here we will check how to list services using netstat command.

To check the services alongside the ports they are listening.

# netstat -pnltu

Output

LPI Study Materials, LPI Guides, LPI Learning, LPI Tutorial and Materials, LPI Online Exam

Viewing /etc/services file


The /etc/services is an ASCII file that contains information about numerous services that client applications might use on the computer. Within the file is the service name, port number and protocol it uses, and any applicable aliases. ITO put t indicates whether a service is TCP or UDP and the name it goes by according to IANA. This information is helpful especially if you are unsure which service is running on which port by default.

To get a clearer picture, view the /etc/services file using a text editor of your choice.

vim /etc/services

Output

LPI Study Materials, LPI Guides, LPI Learning, LPI Tutorial and Materials, LPI Online Exam

Systemd services status check


In newer versions of Linux, Systemd init is present. To check if a service is running, use the syntax below

Syntax

# systemctl status service_name

For example, to check if OpenSSH is running on your system, run

# systemctl status sshd

Output

LPI Study Materials, LPI Guides, LPI Learning, LPI Tutorial and Materials, LPI Online Exam

Alternatively, you can use the syntax below to check if the service is active

# systemctl is-active service_name

In this case, to check if OpenSSH is active,  execute

# systemctl is-active sshd

Output

LPI Study Materials, LPI Guides, LPI Learning, LPI Tutorial and Materials, LPI Online Exam

Also, you can use the command below to check if a service is enabled

# systemctl is-enabled service_name

To check if OpenSSH is enabled, run

# systemctl is-enabled sshd

Output

LPI Study Materials, LPI Guides, LPI Learning, LPI Tutorial and Materials, LPI Online Exam

Checking the status of services in older systems (Centos/Rhel 6.x)


For  systems running SysV Init, you can check the status of services by running

# service service_name status

For example, to check the status of OpenSSH, run

# service sshd status

Output

LPI Study Materials, LPI Guides, LPI Learning, LPI Tutorial and Materials, LPI Online Exam

You can also check all services by running

# chkconfig --list

Output

LPI Study Materials, LPI Guides, LPI Learning, LPI Tutorial and Materials, LPI Online Exam

Related Posts

0 comments:

Post a Comment