Network services registry: On UNIX/Linux systems using inetd (or xinetd historically), which file lists service names and their corresponding TCP/UDP port numbers?

Difficulty: Easy

Correct Answer: /etc/services

Explanation:


Introduction / Context:
Classic UNIX networking stacks map human-readable service names (like http, smtp, ssh) to well-known port numbers. System libraries consult a canonical file for these mappings, enabling tools and daemons to specify services symbolically.



Given Data / Assumptions:

  • The host uses traditional name service files in /etc.
  • inetd/xinetd or network libraries resolve service-to-port mappings from a local database.
  • No special name service switch overrides are considered.


Concept / Approach:

The file /etc/services lists services with their port/protocol pairs (for example, ssh 22/tcp). C library functions like getservbyname consult this database. While many systems now prefer systemd socket activation or stand-alone daemons, /etc/services remains the canonical reference for service names and ports.



Step-by-Step Solution:

Open /etc/services to view mappings such as ftp 21/tcp and http 80/tcp.Confirm a service by running getent services ssh (where supported).Use netstat or ss to correlate listening ports with service names.Update custom services locally by appending new entries if needed (avoid conflicts).Coordinate with firewall rules to allow or block corresponding ports.


Verification / Alternative check:

Check nsswitch behavior in /etc/nsswitch.conf to ensure the services database is consulted locally. Validate resolution using getent services servicename.



Why Other Options Are Wrong:

b: /etc/nsorder is not standard across modern systems.

c: /etc/nsswitch.conf configures name service lookup order; it does not list service-port pairs.

d: /etc/hosts maps hostnames to IP addresses, not ports.

e: Not applicable because /etc/services is correct.



Common Pitfalls:

Confusing service names with daemon binary names; assuming /etc/services changes active daemon ports (it is informational, not authoritative for running daemons); forgetting protocol distinctions (tcp vs udp).



Final Answer:

/etc/services

More Questions from Linux

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion