Running dhclient Software

The philosophy of dhclient is very different from that of most DHCP clients, which assume that users run DHCP because they don't know how to (or don't want to) manually configure TCP/ IP. dhclient assumes that the people running the software are sophisticated users who can easily configure TCP/IP, and who want more than basic configuration from a DHCP client.

Many Linux systems do not include the dhclient software. If your Linux system doesn't have the client, download dhcpd from http://www.isc.org/. The dhcpd distribution includes the dhclient software.

After the client software is installed, it is run using the command dhclient. The command does not require any command-line arguments. When dhclient starts, it reads two files: the configuration file dhclient.conf and the lease file dhclient.leases. You create the configuration file; the lease file is created by dhclient, and is used to preserve information about IP address leases.

The dhclient.leases File

The dhclient.leases file contains a history of the address leases granted to the client. dhclient uses this information for address renewal and to speed the boot process. The leases are stored in a format that dhclient calls lease declarations, which look like the commands in the configuration file. The format of these entries is:

lease { lease-description [... lease-description] }

The lease declaration begins with the lease keyword, followed by one or more lease descriptions. If more than one command is used to describe a lease, they are enclosed in curly braces. The following commands are possible in a lease description:

bootp Means that the lease was acquired from a BootP server rather than a DHCP server.

expire date Defines when dhclient must stop using the address lease if it has not renewed it. date in all of these commands is year, month, day, hour, minute, and second.

filename "path" Defines the pathname of the boot file for diskless clients.

fixed-address address Defines the address assigned by the lease. Despite the name fixed-address, this command is found in all lease statements, even those that assign dynamic addresses.

interface "name" Identifies the interface on which the lease is valid.

option option-name value Defines the value of a configuration option supplied by the server.

rebind date Defines when dhclient should connect to a new server if it has not renewed the address lease.

renew date Defines when dhclient should renew the address lease.

server-name "hostname" Defines the name of the boot server for diskless clients.

Using this information, you can read the dhclient.leases file to see what leases are active and when they expire. The lease declaration can also be used in the dhclient.conf file to manually define an address lease your system can fall back on if no server provides a valid lease. The next section looks at creating a dhclient.conf file.

The dhclient.conf Configuration File

The first—and most important—thing to know about the dhclient.conf file is that you can create an empty one, and dhclient will probably work fine. The dhclient.conf file allows you to change the default settings of the DHCP client. On most networks, this is unnecessary. However, the capability exists if you need to use it.

The manual page for dhclient.conf provides an example of a very complex client configuration. The sample in Listing 8.5 is a somewhat simplified version of that dhclient.conf file

Listing 8.5: A Sample dhclient.conf File

# Set the protocol timers timeout 60;

retry 60; select-timeout 5; reboot 10;

# Define configuration parameters for eth0 interface "eth0" {

send host-name "sparrow.foobirds.org";

send dhcp-client-identifier 1:0:a0:24:ab:fb:9c;

send dhcp-lease-time 28800;

supersede domain-name "foobirds.org";

prepend domain-name-servers 127.0.0.1;

request subnet-mask, broadcast-address, routers, domain-name-servers; require subnet-mask, routers;

# Define a static address for emergencies alias {

interface "eth0";

fixed-address 172.16.5.23;

option subnet-mask 255.255.255.255;

Protocol Timers The first four lines of the sample file set values for the protocol timers used by dhclient:

timeout Sets the maximum number of seconds that dhclient waits for a server to respond. If a server does not provide the client with an offer of an address lease within the timeout period, the client attempts to use any lease in the dhclient.leases file that has not expired, or any static address defined in the dhclient.conf file. The value set in the sample file, 60 seconds, is the default, so this command was not really required.

retry Sets the number of minutes that dhclient waits before it tries again after it failed to get a response from a server. The default is five minutes. In the example, it is set to two minutes.

select-timeout Sets the number of seconds the client waits after receiving information from a server to see if another server responds. More than one server may exist on a network. The servers may be configured differently, and may provide different levels of configuration information to the client, so sometimes it's worthwhile to "wait for a better offer." By default, the client does not wait. It takes the first offer. In the example, dhclient is configured to wait 2 seconds.

reboot Sets the number of seconds the client tries to reacquire the address it used during the last boot. The system assumes that the client will reattach to the same subnet, and that the address it was last using is still available for it to use. Normally, these are very good assumptions, and making them speeds the reboot process. This didn't need to be specified in the configuration because it was set to 10 seconds, which is the default.

The interface Declaration Next comes the interface declaration. The interface declaration is used to define parameters that relate only to a specific interface. It is intended for use on computers that have more than one interface to allow you to configure each interface in a unique way. In the example, there is only one interface, so the command is not required. However, it does no harm, and it illustrates the use of the interface declaration. The curly braces enclose all of the parameters that relate to the specified interface.

send Statements The first three items associated with the interface declaration are send statements, which tell dhclient to fill in values for the specified configuration options before sending the request packet to the server. Any of the options listed in the "dhcpd Configuration Options" section of this chapter, plus the option dhcp-lease-time, can be used in a send statement. Of course, only certain options make any sense when used in this way. Generally, the send statement is used to help the server identify the client. That's what's happening in the sample file with the host-name option and the dhcp-client-identifier option. The dhcp-lease-time option defines the length of the address lease requested by the client. If this option is not specified, dhclient defaults to requesting a two-hour lease. In the example, eight hours (28800 seconds) are requested.

The supersede, prepend, request, and require Commands A supersede command defines a value for a configuration option that is used instead of the value provided by the server. In the example, the domain-name option is defined with a value of foobirds.org. Regardless of the domain-name value provided by the DHCP server, the computer uses foobirds.org as a domain name.

The prepend command also affects the value provided for a configuration option. The value specified on the command line is inserted at the beginning of the list of values assigned to the option. The prepend command can be used only for configuration options that accept a list of values. In the example, the command is used to place the local host at the beginning of the list of name servers.

The request command defines the configuration options that dhclient requests from the server. These are requested in addition to an IP address. Any valid configuration option name can be listed. In the example, the subnet mask, the broadcast address, the default router, and the DNS servers are requested.

The require statement defines the configuration options that the client requires from a DHCP server. If the server does not provide this information, the client will not use any of the configuration information provided by the server. In the example, a subnet mask and a default router are required. As the curly brace indicates, this is the last command in the interface declaration.

The alias Declaration The configuration file ends with an alias declaration, which defines a static address that is used by the client if it does not receive a valid address lease from a server. The example file shows all of the elements of an alias declaration:

• An interface statement to define the interface being assigned an address

• A fixed-address option to define the address

• A subnet-mask configuration option to define the address mask

Other Configuration Commands This sample configuration is much more complex than any configuration you will ever create, but even a complex example such as the one in Listing 8.5 does not cover all of the configuration commands available for dhclient. Following are the other configuration commands you can use:

append {option-list} Adds values to the end of the list of values provided by the server. This statement can be used only for options that allow more than one value. The append command is essentially the opposite of the prepend command described earlier.

backoff-cutoff time Defines the maximum amount of time that the client is allowed to back off on configuration requests. The default is two minutes. A randomized exponential back-off algorithm prevents clients from all trying to configure themselves at the same time. This value prevents the client from backing off for an excessive amount of time.

default {option-list} Sets values for options that are used if the server does not supply the values. If the server provides a value, it is used; otherwise, the value defined here is used. For example, to make sure the client has a subnet mask, even if one is not provided by the server, you might enter the following:

default subnet-mask 255.255.255.0;

initial-interval time Sets the time interval that is multiplied by a random number between zero and one to determine the amount of time the client backs off between attempts to reach a server. The time between attempts is doubled on each failed attempt. If it exceeds the backoff-cutoff amount, it is set to that amount. The default time interval is 10 seconds.

media "media setup" [ , ... ] Defines media configuration parameters for network interfaces that aren't capable of sensing the media type unaided.

reject address DHCP offers from the server at the specified address are ignored.

script "path" Identifies the dhclient configuration script file. This is a script that configures the local system's network interface with the values learned from the DHCP server. For more information, see the manual page for dhclient-script.

Looking at this large configuration language and the complex example, you may be wondering why you would do this. After all, this is at least as challenging as statically configuring TCP/IP with ifconfig. The reason is primarily for mobility. A computer consultant may need to move a Linux laptop from network to network in the course of a business day. A tool such as dhclient eliminates the need to manually reconfigure the system every time it is attached to a new network.

Was this article helpful?

0 0

Post a comment