Unix Power ToolsUnix Power ToolsSearch this book

46.2. /etc/services Is Your Friend

After you've been dealing with Internet services for a while, you come to remember certain well-known port numbers off of the top of your head. SMTP (Section 46.8) is port 25, HTTP is port 80, and so on. However, unless your memory is far better than mine, you won't remember them all.

Luckily, that's part of what /etc/services is for. It's a database of well-known ports with symbolic names; any program that can take a port number should be able to take the appropriate symbolic name instead. If you want to make sure your SMTP server is up, the following two commands are equivalent:

% telnet localhost 25
% telnet localhost smtp

The definitive database of well-known ports is currently available at http://www.iana.org/assignments/port-numbers. On most Unixes, /etc/services is just a snapshot taken at the time that version of that Unix was released. When installing new services, often you'll want to tweak your local copy of /etc/services to reflect the new service, if it's not already there, even if only as a reminder.

The format of the /etc/services is simple:

service name        port/protocol        aliases

Comments within the file start with a pound sign (#). As an example, a few common entries from /etc/services:

ftp-data         20/tcp    #File Transfer [Default Data]
ftp-data         20/udp    #File Transfer [Default Data]
ftp              21/tcp    #File Transfer [Control]
ftp              21/udp    #File Transfer [Control]
ssh              22/tcp    #Secure Shell Login
ssh              22/udp    #Secure Shell Login
telnet           23/tcp
telnet           23/udp
smtp             25/tcp    mail         #Simple Mail Transfer
smtp             25/udp    mail         #Simple Mail Transfer

-- DJPH



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.