Ports

As a general (but far from absolute) rule each computer only has one Internet address. However, computers often need to communicate with more than one host at a time. For example, there may be multiple ftp sessions, a few web connections, and a chat program all running at the same time.

To make this possible the computer's network interface is logically subdivided into 65,536 different ports. This is an abstraction. A port does not represent anything physical like a serial or parallel port. However as data traverses the Internet in packets, each packet carries not only the address of the host but also the port on that host to which it's aimed. The host is responsible for reading the port number from each packet it receives to decide which program should receive that chunk of data.

If you like, you can think of the packets as letters sent via snail mail, the IP address like the street address. Then the port is the apartment or suite number. The routers that move packets from one location to another only worry about the street address. They don't have to read the port. Only the final destination has to do that.

On Unix systems you must be root to listen for connections on ports between 1 and 1023. Anyone can listen for connections on ports of 1025 to 65,535 as long as the port is not already occupied. (No more than one program can listen on a given TCP port at the same time.) However on Windows NT, Windows 95, and the Mac any user can listen to any port. No special privileges are required.

Any remote host can connect to a server that's listening on a port below 1024. Furthermore, multiple simultaneous connections may be made to a remote host on a remote port. for example, a high volume web server listening on port 80 may be processing several dozen connections at the same time, all connected to port 80.

In short, no more than one process on the local host can use a port at one time. However many remot hosts may connect to the same remote port.

Many services run on well-known ports. This means that the protocol specifies that the service should or must use a particular port. For example http servers generally listen on port 80. SMTP servers listen for connections on port 25. Echo servers listen on port 7. Discard servers listen on port 9. Not all services have a well-known port. For example, NFS allows the ports to be discovered at runtime.


Previous | Next | Top | Cafe au Lait

Copyright 1997 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified September 15, 1997