Search the Catalog
Learning Debian GNU/Linux

Learning Debian GNU/Linux

By Bill McCarty
1st Edition September 1999
1-56592-705-2, Order Number: 7052
360 pages, $34.95 , Includes CD-ROM


Previous: 10.1 Introduction Chapter 10
Setting Up a Linux-Based LAN
Next: 10.3 Samba
 

10.2 Network Administration

The Debian GNU/Linux install program lets you specify a network configuration that's used when your system is first booted. If your network configuration changes, you can re-install Linux. However, you can spare yourself much inconvenience by learning how Linux stores its network configuration. As you'll see, by using a text editor to revise some files, you can alter your system's network configuration without going through the pain of re-installing Linux.

10.2.1 Network Hardware Configuration

If you replace your network adapter card with a different model card, you must run the modconf program, which lets you specify the driver that operates your card. To do so, simply login as root and type the command:

modconf

You're already familiar with the modconf program. It's the same program you used to specify drivers when you originally installed Linux. If you have difficulty using modconf, refer to the section titled Section 3.1.2.13, "Configuring device driver modules" in Chapter 3, Installing Linux. You must reboot your system before changes made by modconf take effect.

10.2.2 Basic Host Information

When you installed Linux, you specified a hostname for your system. If you want to change the hostname associated with your system, you can edit the file /etc/hostname by using ae or another editor of your choosing. Because the file - like most configuration files - has restrictive permissions, you must login as root in order to modify it.

The format of the /etc/hostname file is simple. The file contains a single line, which contains the hostname of your system; for example, debian. If you change the hostname, be sure to specify only the hostname itself; do not specify a fully qualified hostname that includes the domain name (for example, debian.ora.com).

10.2.3 Name Server Specification

When you installed Linux, you may have specified one or more nameservers. Your system accesses a nameserver when it needs to determine the network address that corresponds to a hostname. If your network configuration changes, you may need to specify a new nameserver or servers. Your ISP should provide you with the proper IP address or addresses.

The network addresses of your system's name servers are specified in the file /etc/resolv.conf, which you can edit by using ae or another editor while logged in as root. The format of the file is simple, though not as simple as that of the /etc/hostname file. To specify a name server, include a line of the form:

nameserver 
xxx.xxx.xxx.xxx

where xxx.xxx.xxx.xxx denotes the network address (IP number) of the name server; for example, 192.168.1.1. You can include as many as three such lines; when your system needs to determine a network address, it will attempt to contact the name server specified by the first such line. If that server is unavailable, your system will attempt to contact the name server specified in the second such line, if any. If that werver is unavailable, your system will contact the name server specified in the third such line, if any.

10.2.4 Routing and Gateways

If your computer is part of a local area network attached to the Internet, your computer doesn't generally send data packets directly to Internet hosts. Instead, it sends data packets to a designated computer - called the gateway - on the local area network. The gateway forwards data packets to the Internet on behalf of your system. It also performs the complementary service, forwarding data packets from Internet hosts to your system.

NOTE: If your system connects to the Internet via PPP, the PPP system establishes a network configuation dynamically. You'll learn how this works in the next chapter.

The information that describes your local area network is contained in the file /etc/init.d/network, which you can easily edit. Here's a typical /etc/init.d/network file:

#! /bin/sh
inconfig lo 127.0.0.1
route add -net 127.0.0.0
IPADDR=192.168.1.10
NETMASK=255.255.255.0
BROADCAST=192.168.1.255
GATEWAY=192.168.1.1
ifconfig eth0 ${IPADDR} netmask ${NETMASK} broadcast ${BROADCAST}
route add default qw ${GATEWAY} metric 1

The lines you're concerned with are the lines four through eight, each of which has the following form:


variable=
ipnumber

The lines associate a name, given by variable, with a network address, given by ipnumber. The variables are referenced by the following three lines, which are commands that configure networking.

To change your network configuration, you need merely to associate the proper IP number with each variable. You can do so by logging in as root and modifying the /etc/init.d/network file by using a text editor. Table 10.1 describes each variable. Your network administrator should be able to provide you with the proper values.


Table 10.1: Network Configuration Variables

Variable

Meaning

IPADDR

Specifies the network address of your system.

NETMASK

Specifies the network address of your network, by indicating which bits of the 32-bit network address of your system pertain to the network and which pertain to the system. Many local area networks are so-called Class C networks, which require a netmask of 255.255.255.0.

BROADCAST

Specifies the address used to send a message to every system on the local area network. Often you can determine the broadcast address of a local area network from the address of a system on the local area network: simply replace the last of the four components of the network address of the host by 255.

GATEWAY

Specifies the network address of the gateway used by your system.

10.2.5 Hostname Search Path

Your Linux system can use as many as three methods to determine the IP address that corresponds to a hostname. Your system can:

  • Query a DNS server (you configured your system's DNS client earlier)

  • Read the contents of the file /etc/hosts, known as the hosts file, which you'll learn about in the next subsection

  • Query an NIS (Network Information System) server

However, unless your system is part of a sophisticated local area network, it's unlikely that an NIS server is available. Therefore, most systems can query a DNS server and, failing to obtain an answer, read the /etc/hosts file. Alternatively, most systems can read the etc/hosts file and, failing to obtain an answer, query a DNS server. The second alternative is generally better, because reading the /etc/hosts file takes less time than querying a DNS server.

The /etc/host.conf/ file specifies which of these three operations are performed, and the order in which they're attempted. You can edit this file by logging in as root. Here's a typical file:

order hosts,bind
multi on

The order line specifies that the system should first consult the /etc/hosts file and then query a DNS server, referred to as bind because of the Berkeley Internet Name Daemon, an early DNS server.

The multi line specifies that your system will attempt to locate all possible names for a host when it reads the /etc/hosts file. Unless that file is very large (hundreds or thousands of lines), you should include the multi line.

10.2.6 Miscellaneous Network Configuration Options

The hosts file, /etc/hosts, lets your system determine the network address number that corresponds to a hostname, without querying a DNS server. Besides being faster than querying a DNS server, the /etc/hosts file is always available.

Entries in the file have two parts:

  • an IP address

  • a hostname, or a list of hostnames separated by spaces

By default, the hosts file contains an entry that associates the hostname localhost with the IP address 127.0.0.1. It's not necessary that you include any other entries in the /etc/hosts file. However, most system administrators include at least a second line, which associates the local hostname with its network address. Here's a typical file:

127.0.0.1      localhost
192.168.1.10   debian.mccarty.org debian

Notice that the second line gives both the fully qualified hostname, consisting of the hostname and domain name, as well as the hostname alone.

The /etc/networks file, known as the networks file, performs a function similar to that of the hosts file; whereas the hosts file associates hostnames with network addresses, the networks file associates networks' names with network addresses. By default, the networks file contains a single line associating the network address of the local area network with the name localnet:

localnet 192.168.1.0

Generally, it's not necessary that you add other entries to the networks file. However, by doing so, you can access frequently used networks by name even if your DNS server is unavailable.



Previous: 10.1 Introduction Learning Debian GNU/Linux Next: 10.3 Samba
10.1 Introduction Book Index 10.3 Samba

Back to: Learning Debian GNU/Linux


oreilly.com Home | O'Reilly Bookstores | How to Order | O'Reilly Contacts
International | About O'Reilly | Affiliated Companies | Privacy Policy

© 2001, O'Reilly & Associates, Inc.