2 How to look for services

On a Debian system, a list of services is available at /etc/services. A description of the file can be accessed by the command man services. This file does not control services, but it assigns names to port numbers.

If a service is handled by inetd, the controling file is /etc/inetd.conf. Any line that does not start with a pound # symbol sets up a helper server program. You can use the command man inetd.conf to read the system’s own manual on this file.

The important part is to search for a line that does not start with a pound (#) symbol. Such a line specifies that a particular service (first item of the line) is handled by a specific server program (last entry on a line). On a default Debian system, IDENT should be the only service handled by inetd.

Other services can be handled by standalone daemons. These services include SSH, HTTP and many others. To find out which ports are being “listened” by a daemon, use the following command:

nmap -sT -O localhost  
  

This command runs a port scan against “localhost”, which means the machine that is running the scan. It lists the ports that are being listened. Note that if a machine has anti-scanning measures in place, this command can cause a false alarm.

Another method is to use the following command:

netstat -plnt  
  

This command lists listening ports. Note that some ports are listed by numbers, and others listed by name. The ones listed by names are the ones defined in /etc/services. You only need to focus on the first part of the output, where the word LISTEN is on the right hand side.

The netstat command should not cause any false alarm. Here is how a line is interpreted (some extra spaces removed):

tcp   0   0 0.0.0.0:2222   0.0.0.0:*   LISTEN   3492/sshd  
  

Take a good look at the output of nmap and netstat. This gives you an idea of which ports are being listened to.