-->
Previous Table of Contents Next


Chapter 24
Configuring a TCP/IP Network

by Steve Burnett

In this chapter
Understanding the TCP/IP Configuration Files
Initializing Ethernet Interfaces
Understanding TCP/IP Routing
Monitoring a TCP/IP Network with netstat

Configuring a TCP/IP network is one of the more common tasks you’ll face when administering Linux machines. In the most basic cases, it’s not very complex, but it does require a bit of thought on the design of your network and knowledge of a small number of programs and configuration files.

Understanding the TCP/IP Configuration Files

TCP/IP networking in Linux is controlled by a set of configuration files in the /etc directory. These files tell Linux what its IP address, host name, and domain name are and also control the network interfaces. Table 24.1 shows you what each file does; the following sections discuss these files in detail.

Table 24.1 Linux TCP/IP Networking Configuration Files

File Description

/etc/hosts Maps host names to IP addresses
/etc/networks Maps domain names to network addresses
/etc/rc.d/rc3.d/S10network Configures and activates your Ethernet interfaces at boot time

The /etc/hosts File

Every computer on a TCP/IP network has an IP address, canonical host name, and zero or more host name aliases. The /etc/hosts file is the original method for mapping host names to IP addresses.


NOTE:  All host names, domain names, and IP addresses used in this chapter are fictitious and don’t reflect any true network on the Internet.

For illustrative purposes, look at the network that Burwell, Inc. has built. This network consists of the single class B network address assigned to Burwell by InterNIC (the organization that controls Internet addresses); this network has been split into two class C subnetworks. The format for the hosts file is as follows:


# /etc/hosts for linux1.burwell.com

#

# For loopbacking.

127.0.0.1     localhost



# This machine

166.82.1.21     linux1.burwell.com linux1     # the local machine



# Other hosts on our network

166.82.1.20     server.burwell.com server     # the server

166.82.1.22     wk1.burwell.com               # workstation 1

166.82.1.10     netpr1.burwell.com netpr1     # networked printer

166.82.1.1     gateway.burwell.com gateway     # the router

166.82.1.1     gate-if1               # 1st interface on gateway

166.82.2.1     gate-if2               # 2nd interface on gateway

166.82.1.30     linux2.burwell.com linux2     # Laptop via PLIP



# end of hosts file


TIP:  Notice that the preceding gateway has two host names for the IP address 166.82.1.1. Giving a unique name to each network interface on a machine is a good idea. Doing so makes it easier to see what’s going on when you use the ifconfig and route commands.

The format of the hosts file consists of one IP address per line beginning in the first column, the canonical host name associated with that address, and then zero or more aliases. The fields are separated by spaces or tabs. Empty lines and text following a # character are treated as comments and are ignored.

The IP address 127.0.0.1 is known as the local loopback address and is reserved for this purpose. It’s normally assigned the name localhost. If you’re going to use your machine only as a standalone system or use SLIP or PPP to connect to the outside world, you need only the localhost address in your hosts file.


NOTE:  The function of the /etc/hosts file has been mostly taken over by Domain Name Service (DNS) on machines connected to the Internet or large internal networks. DNS isn’t available during boot or when you’re running in single-user mode, however, so it’s a good idea to place the information for essential machines such as servers and gateways in /etc/hosts.

On a network with only a few machines that aren’t connected to the Internet, it’s easier to keep a complete listing of all hosts in /etc/hosts rather than configure and maintain DNS.



TIP:  Naming your networks makes it convenient to do things such as static routing that take a host name or network name. You don’t have to remember the subnets by their IP addresses, just their names.

The /etc/networks File

Just as hosts have names and IP addresses, networks and subnets can be named. This naming is handled by the /etc/networks file. The IP addresses in the networks file include only the network address portion plus the subnetwork byte. The following is an example file for burwell.com:


# /etc/networks for burwell.com



localnet     127.0.0.0      # software loopback network

burwell-c1     166.82.1     # Development Group Network, Class C

burwell-c2     166.82.2     # MIS Network, Class C



# end of networks file

First is the localnet name and IP address, 127.0.0.0. If you aren’t connecting your Linux machine to a TCP/IP network or are using only SLIP or PPP, all you need to put in this file is the localnet name and IP address.

The next lines identify the two class C subnetworks that Burwell has made from its class B network.

Initializing Ethernet Interfaces

The ifconfig program makes network interfaces such as the software loopback and Ethernet cards known to the Linux kernel, so that Linux can use them. The ifconfig program is also used to monitor and change the state of network interfaces. A simple invocation of ifconfig is


ifconfig interface address

which activates the specified network interface and assigns an IP address to it. This is called bringing up an interface. The generalized calling syntax for ifconfig is as follows:


ifconfig interface [aftype ] [options ] |  address


Previous Table of Contents Next