/etc/services
The /etc/services file on Unix-like operating systems is a crucial configuration file that maps network service names to port numbers and protocols. This file helps the operating system and applications identify which port numbers should be used for specific network services. It serves as a reference for both TCP and UDP port assignments and is used by various network services and tools.
Structure of /etc/services
/etc/servicesThe file typically contains lines formatted as follows:
service_name port/protocol [aliases...]Here's a breakdown of each field:
service_name: The name of the service or application using the port.port: The port number assigned to the service.protocol: The transport protocol used by the service (tcp,udp, etc.).aliases(optional): Alternative names for the service.
Example Entries
Here's a snippet from a typical /etc/services file:
http 80/tcp
https 443/tcp
ftp 21/tcp
smtp 25/tcp
ssh 22/tcp
domain 53/udpCommon Entries
httpPort Number: 80
Protocol: TCP
Description: Used for HTTP web traffic.
httpsPort Number: 443
Protocol: TCP
Description: Used for HTTPS secure web traffic.
ftpPort Number: 21
Protocol: TCP
Description: Used for FTP file transfer.
smtpPort Number: 25
Protocol: TCP
Description: Used for SMTP email sending.
sshPort Number: 22
Protocol: TCP
Description: Used for SSH secure shell access.
domainPort Number: 53
Protocol: UDP
Description: Used for DNS queries.
Usage
The /etc/services file is used by various system utilities and network programs, such as:
netstat: Displays network connections, routing tables, and interface statistics. It relies on/etc/servicesto provide human-readable service names.ss: A utility to investigate sockets, also uses/etc/servicesfor service name resolution.nmap: A network scanner that uses/etc/servicesto map scanned ports to service names.
Managing /etc/services
/etc/servicesEditing: Directly edit the file using a text editor like
viornanoto add or change service definitions. Ensure to have superuser permissions.sudo nano /etc/servicesAdding Custom Services: You can add your own custom services for internal use. Just ensure that they do not conflict with existing entries.
Example of Adding a Custom Service
To add a custom service:
Open the file in a text editor with superuser privileges:
sudo nano /etc/servicesAdd a new line for your service:
myservice 12345/tcpSave and exit the editor.
Conclusion
The /etc/services file is a fundamental part of Unix-like systems that helps in mapping network services to their respective ports and protocols. While it is not frequently changed, understanding its format and function is essential for network configuration and troubleshooting.
Last updated