Files for Setting Network Options

In many cases, the files described in Table 19.1 control static IP address configuration as well as DHCP options. For instance, Listing 19.1 shows a SuSE system's static IP

address configuration, as defined in /etc/sysconfig/network/ifcfg-ethO.

Listing 19.1: Typical Options in a Static IP Address Configuration File



Most of the entries in Listing 19.1 are self-explanatory, at least if you know the terminology, as summarized earlier, in "TCP/IP Basics." Many distributions use the BOOTPROTO variable to set the method of network configuration—static for a static IP address or dhcp for DHCP. The STARTMODE option in Listing 19.1 tells the system to start networking when the system boots. UNIQUE is a system-specific ID code. You can change these options, or options such as the IPADDR and NETMASK, to change the static IP address configuration.

The computer's hostname often appears in a file called /etc/hostname or /etc/HOSTNAME. Many networking tools use the name in this file when announcing the system to other computers or in displays such as login prompts. The /etc/hosts file also sets the hostname, along with the computer's IP address, in lines like these: localhost trex

This file serves as a sort of mini-DNS; it can provide static mapping of IP addresses to hostnames. This file usually contains both a mapping of to localhost and an entry for the machine's network IP address and hostname. The latter entry includes both the fully qualified domain name (FQDN; and a shorter "nickname" (trex). Small networks sometimes use /etc/hosts entries to enable users to type computer hostnames rather than IP addresses without running a full DNS server.

Tip If your computer takes a long time to start up, including a pause when starting sendmail, check/etc/hosts. Some programs pause for long periods if they can't resolve the computer's hostname to an IP address. If DNS isn't working at that point in the boot process, a properly configured /etc/hosts file can bypass problems.

Another important network configuration file is/etc/resolv.conf. This file holds information on DNS servers. Listing 19.2 shows a typical resolv.conf file. The nameserver lines are the most important ones; each of these lines points to one DNS server. If one DNS server doesn't respond, Linux tries the next one, and then a third, if defined. The domain line specifies the domain in which the computer resides. You can omit the name of the domain ( in Listing 19.2) from a hostname during a lookup; for instance, entering http://trex in a web browser will find the web server running on The search line accomplishes a similar goal, but you can specify several search domains. Searching many domains can slow down name resolution, though, and may return the wrong IP address sometimes, if a name is duplicated in two domains.

Listing 19.2: Contents of a Typical /etc/resolv.conf File domain search nameserver nameserver

One final but very important configuration file is your distribution's local startup file, as described in Chapter 9. Most network options can be set by calling networking programs, such as route or ifconfig, from a local startup file. For instance, the following lines bring up ethO and assign it a default route (the local gateway system) of

ifconfig ethO up route add default gw

0 0

Post a comment