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

BOOTPROTO-static'

BROADCASTS 92.168.1.255' IPADDR='192.168.1.1' NETMASK='255.255.255.0' NETWORK='192.168.1.0' REMOTE_IPADDR=" STARTMODE='onboot' UNIQUE='WL76.hvctWyU2jj4' WIRELESS='no'

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:

127.0.0.1 localhost 192.168.1.1 trex.pangaea.edu 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 127.0.0.1 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; trex.pangaea.edu) 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 (pangaea.edu 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 trex.pangaea.edu. 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 pangaea.edu search north.pangaea.edu south.pangaea.edu nameserver 172.30.9.7 nameserver 192.168.1.1

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 192.168.1.1:

ifconfig ethO up route add default gw 192.168.1.1

0 0

Post a comment