TCP/IP Hosts and Services Files

There are two files used to configure TCP/IP connections. The purpose of these files is to allow the use of symbolic names rather than port numbers and IP addresses.

IP Addresses and the Hosts File

IP addresses are internet format numbers with four parts. For example, 123.456.789.012. The hosts file provides a list of IP addresses and aliases (that is, names) for them. For example, here is a typical line in a hosts file:
123.456.789.012    elmo      Elmo     ELMO
The first part is the IP address. The next three columns say that elmo, Elmo, or ELMO can be used to refer to the machine configured as 123.456.789.012.

Configuration of a machine at an IP address differs among various TCP/IP systems. The information in the hosts file typically refers to the IP addresses of other machines on the network.

Port Numbers and the Services File

TCP/IP port numbers are not physical addresses on a computer. They are, rather, logical addresses used to associate a particular "service" with a connection.

To use a service, both sides of the connection must know either the name or the port number of the service. The services file provides a way to associate a name with a port number. This allows programs to use the name. The services file on both sides of the connection (which may or may not be the same file) must associate the name with the same port number. The port number can be any number not currently in use on the network.

Here are two lines from a services file typically used with CQL++:

CQLISAM        8000/tcp        # CQL ISAM server
CQL            8010/tcp        # CQL SQL server
The information after # is a comment. The first line associates the name CQLISAM with port 8000. The second line associates the name CQL with port 8010. The /tcp after the port number indicates that a TCP/IP port is being defined.

When this information is in the services file(s), programs can use the names CQLISAM and CQL instead of using port numbers directly. Network administrators can then adjust the port numbers if necessary with no program changes.

Location of Hosts and Services Files

The location of the hosts and services files varies from system to system. For UNIX systems, expect to find them in the /etc directory. To edit the UNIX hosts and serviceshosts and services file. Instead, there may be a hosts.sam (for hosts.sample) and services.sam (for services.sample) file. Copy hosts.sam to hosts, and copy services.sam to services, and then edit the files.