Check Apache Service Name in Linux

Posted on

One thing which is very important for monitoring running service in an operating system is knowing the name of that running service. It is the same case with any running service available including Apache Webserver which is responsible handling for web request.

First of all, in main Linux or Unix operating system distribution there is a list of service available in the operating system which is mapped to the port number provided for handling service request. Since the service handling web request is normally configured in port 80, all we need to do is to find whether the service is available or not in the installed operating system. It can be achieved by executing the following command :

cat /etc/services | grep 80

Description  :
cat : It is a command which is used to read the content of a file sequentially and display the content read into standard output in this context for an example monitor screen. 
/etc/services : It is a the path of services file 
| : It is the sign which is used to direct the output of the command specified before the '|' sign to be the input of anything exist after the '|' sign 
grep : It is a command which is used to search text from a given output of given file with a specific pattern search.  
80 : The value which is feeded to the grep command

The above command’s purpose is reading all the content of file services located in /etc directory and pass it to be searched further for text containing ’80’.

The above command is used to print the content of file services located in /etc. This is the output display of the command execution :

root@hostname:~# cat /etc/services | grep 80
http            80/tcp          www             # WorldWideWeb HTTP
http            80/udp          root            # HyperText Transfer Protocol
socks           1080/tcp                        # socks proxy server
socks           1080/udp
http-alt        8080/tcp        webcache        # WWW caching service
http-alt        8080/udp
nbd             10809/tcp                       # Linux Network Block Device
amanda          10080/tcp                       # amanda backup services
amanda          10080/udp
omirr           808/tcp         omirrd          # online mirror
omirr           808/udp         omirrd
canna           5680/tcp                        # cannaserver
zope-ftp        8021/tcp                        # zope management by ftp
tproxy          8081/tcp                        # Transparent Proxy
omniorb         8088/tcp                        # OmniORB
omniorb         8088/udp

As shown in the above output, it can be realized that the WorldWideWeb HTTP service is handled by opening port 80 which is the default port for web request. Using the information regarding listening port, we can try to get further information about service name :

netstat -tlpn | grep port_number

Description : 
netstat : It is a utility which also a command that can be executed in the command line. It can be assumed as an abbreviation of network statistics. It is used to 

In computing, netstat (network statistics) is a command-line network utility tool that displays network connections for the Transmission Control Protocol (both incoming and outgoing), routing tables, and a number of network interface (network interface controller or software-defined network interface) and network protocol statistics. 
-t : It is a parameter for netstat command which is filtering the output to show onlyl for the one associate with TCP Packet. 
-l : It is a parameter for netstat command which is filtering the output to show only for the listening port.  
-p : It is a parameter for netstat command which is filtering the output to show the PID and program name. 
-n : It is a parameter which is used to display addresses and port in a numerical form.

This is how we use the command to search for the service name associated with Apache Webserver runs in port 80 below :

root@hostname:~# netstat -tlpn | grep 80
tcp6       0      0 :::80                   :::*                    LISTEN      20039/apache2

As shown in the above output, it is clearly shown that the service name is apache2. It can be derived from the above command.

Leave a Reply