The portmapper is a server process one will often find running on Unix servers. Common Unix services such as NIS and NFS rely on this bit of infrastructure.

A bit of background to start. Unix server processes, or daemons, usually listen on a TCP/IP port for network connections. A familiar example is a web server: it will listen on its port until a web browser connects and asks it to deliver a page. The web browser usually listens on a well-known port, which happens to be port 80. Many internet services have well-known ports that are used by convention. FTP uses port 21, telnet uses port 23, IMAP uses port 143, and so on (a more complete list can be found in /etc/services or %WINDIR%\system32\drivers\etc, depending on your OS).

In the early days of the internet, Sun came along and decided to base their new services on a library called RPC. RPC, or remote procedure calls, is a high level library that allows a program to be split up into client and server, mostly transparently. They wanted to make RPC virtually painless to use, so they had to address network configuration. In particular, how would the client side of an RPC program program know on which port to contact the server? Two servers that chose the same port wouldn't be able to coexist on the computer. Sun also wanted to avoid taxing the already scarce resource of reserved ports. So rather than requiring all RPC programs to reserve their own RPC ports, Sun built a program that assigned them dynamically at runtime: the portmapper.

The portmapper does one thing - it maps RPC requests to ports. An RPC server will register itself with the portmapper on startup to find a free port, which it will then listen on. The RPC client then contacts the portmapper and asks it what port to use to contact the server. Both the client and server know how to contact the portmapper: it uses the well-known port 111. The portmapper usually uses a map of programs to ports located in /etc/rpc for common RPC-based programs, but this is a convenience only; the port mapper will find an appropriate port if no entry is found. The rpcinfo utility can be used to determine which programs are currently registered with the portmapper with rpcinfo -p hostname.

The advantage of dynamically assigning ports this way is obvious. First, it protects against port number conflicts, where two or more servers want to use the same port. Server installation is simplified by removing any need to update /etc/services. And finally, it allows the network client to be ignorant of the details of the server until it is run.