0

In /etc/services, a service name can have multiple (transport protocol, port number) pairs. For example, The Linux Programming Interface says:

The /etc/services file consists of lines containing three columns, as shown in the following examples:

# Service name  port/protocol  [aliases]

http            80/tcp                  # Hypertext Transfer Protocol
http            80/udp
ssh             22/tcp                  # Secure Shell
ssh             22/udp
telnet          23/tcp                  # Telnet
telnet          23/udp
smtp            25/tcp                  # Simple Mail Transfer Protocol
smtp            25/udp

Which field(s) can be a key in the table?

The example shows a service name can correspond to more than one transport protocols.

Given a service name and a transport protocol, can they correspond to more than one port numbers? In other words, can a service listen at two ports in the same transport protocol?

Thanks.

4

The file is described in the services(5) manpage, and its usage in the related functions’ manpage. The latter shows that the following pairs are expected to be keys:

  • name and protocol;
  • port number and protocol.

Note that services can have aliases (which your example doesn’t illustrate). www for instance is typically an alias for http:

http            80/tcp          www             # WorldWideWeb HTTP

Regarding what services can do, /etc/services only provides a mapping, it doesn’t constrain anything. Thus, someone asking for http on TCP will be told that the corresponding assigned port is 80, but an HTTP dæmon can listen on any port it wants to (and is allowed to); likewise, someone asking for port 80 on TCP will be told that the corresponding name is http, but that doesn’t mean that a server listening on port 80 has to be an HTTP server. Furthermore, single processes can listen on multiple ports, and on BSDs and Linux since kernel 3.9, multiple processes can listen on the same port.

  • Thanks. "can a service listen at two ports in the same transport protocol?" – Tim Feb 13 at 21:53
  • The key (uniqueness) requirement answers that, doesn’t it? – Stephen Kitt Feb 13 at 21:54
  • Is it correct that a service can only listen at one port in a transport protocol, and a process can listen at two ports in the same transport protocol (so the process actually runs two services)? – Tim Feb 13 at 21:56
  • Can a service have two ports in the same transport protocol for its listening purpose? – Tim Feb 13 at 22:19
  • 1
    We’ve gone a long way from “which field(s) can be a key in the table in /etc/services?” at this point... – Stephen Kitt Feb 14 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.