|
Also in Linux Network Administration: Exploring the /proc/net/ Directory |
In many networks, IP addresses are manually assigned to hosts. There are a number of reasons why for most hosts this is an unnecessary and even undesirable arrangement.
In this column we'll describe how to manage the automatic allocation of IP addresses (and other useful information) in a Linux environment for hosts connected to a broadcast-style network like Ethernet. For convenience, we'll refer to these networks as Ethernet, but the same principles apply to many different types of underlying protocols such as FDDI, Token Ring, and AX.25.
There are a number of situations where dynamic IP address assignment provides benefit. Some of the more important of these are:
Dynamic address assignment isn't all good news. There are a number of situations where it is inappropriate, and some where it complicates management.
ssh) can also rely on the IP address of a host as part of the authentication credentials required to open a session to it.There are three well-known protocols that manage dynamic IP address assignment for Ethernet networks; a brief description of each follows. If you want an exhaustive description of each protocol, see the relevant RFC documents.
All three protocols are related and make a nice study of evolutionary development and innovation should you be a history buff.
The Reverse Address Resolution Protocol (RARP) complements the Address Resolution Protocol (ARP) and was designed specifically with diskless workstations in mind.
The ARP protocol is used by hosts wishing to discover the hardware address associated with a particular IP address. The RARP protocol operates in reverse by enabling a host that knows its hardware address to request and discover its IP address by transmitting a specially formulated broadcast query to a RARP server on the same network. The RARP server upon receiving such a request, searches a database to find an IP address associated with the hardware address of the requesting host and replies directly to the requester, offering the IP address that host should use. This is the extent of the RARP protocol.
Unfortunately, in many situations hosts need to learn more than their IP address in order to boot and operate. RARP is not very commonly used any more, but is still sometimes useful -- especially if you are installing Linux on a Sun workstation. Linux implementations of both client and server exist. The man pages supplied with the software should be perfectly adequate to explain how to use it.
The Bootstrap Protocol appeared shortly after RARP and addresses two important limitations. First, rather than being based on hardware-layer protocols, it is completely UDP/IP-based, making it somewhat easier to implement. A BootP transaction also supplies more than the IP address the client host should use, it additionally supplies the address of a boot file and the address of the server the boot file should be retrieved from.
BootP is quite simple. The cilent host builds a "bootrequest" message. In this message it places its hardware address. It transmits this message onto the network in a UDP/IP datagram with source port 68 and destination port 67. If the client knows the address of the BootP server, it places the server's address in the IP destination address field, if not it uses the broadcast address 255.255.255.255 (ref: RFC-919) instead.
The BootP server upon receiving a "bootrequest" message consults its local database, searching for an IP address mapped against the hardware address supplied. If a match is found, the BootP server formulates a "bootreply" message containing the IP address allocated and transmits the response to the IP broadcast address. BootP provides space in a "bootreply" message for vendor-specific information.
This mechanism allows a range of other configuration information and data to be provided to the requesting host. RFC-1497, "BOOTP Vendor Information Extensions" describes in detail how this works and defines the coding a wide range of possible configuration data. Suffice it to say, the BootP implementations available for Linux save you the pain of of having to deal at this level by providing direct keyword support for most of these.
|
DHCP leverages off the success of BootP and extends it by defining mechanisms for IP address allocation with a wide range of configuration data. DHCP describes backward-compatability with BootP, ensuring that BootP clients can effectively make use of a DHCP server without reconfiguration. DHCP servers can make use of the BootP relay feature provided by many routers.
DHCP describes three types of IP address allocation:
An important concept that DHCP introduces is the idea of "lease" time for an address. A DHCP client may request an address for a period of time, and the DHCP server guarantees not to reallocate the address to another host within that time. The client may, of course, make another request for an address at the expiration of the lease, and the DHCP server will attempt to reallocate the same address when this occurs.
The DHCP implementation most commonly found on Linux systems is that produced by the Internet Software Consortium. It will be available pre-packaged in just about all Linux distributions.
DHCP is easily the most commonly used dynamic address assignment mechanism as just about every desktop machine supports it, and many ADSL and cable-modem providers also use it.
Let's move on and start configuring. First, some assumptions:
192.168.1.0 and 192.168.2.0. In each, we will dynamically allocate addresses from the range .32-.254 to hosts. The remainder of the addresses are reserved for use by application servers, routers, and other shared infrastructure..1 on it. testnet.net domain and there is a shared name server with address 192.168.2.16.The configuration file for the ISC DHCP daemon is named /etc/dhcpd.conf and contains two types of statements, parameter statements and declaration statements. The parameter statements supply values for a number of DHCP variables such as lease times, and data to supply to client hosts such as gateway addresses. Declaration statements are used to describe collections of hosts to manage and collections of parameter statements to supply to hosts. Parameter statements can appear outside declaration statements and are then considered global parameters, or they may appear within declaration statements and then apply only to the hosts described by that declaration. Parameter statements are terminated with the ; character and declarations are enclosed within the curly brace {} characters.
You can build quite sophisticated configurations, but in most cases a simple one is all that is required. A configuration to meet the requirements specified for our network described above might look something like:
# dhcpd.conf - configuration for simple network
# Our global default configurations
option domain-name "testnet.net";
option domain-name-servers 192.168.2.16;
option subnet-mask 255.255.255.0
default-lease-time 600;
max-lease-time 7200;
# On our .1 subnet we will dynamically allocate
# address to any host that requests one using
# either DHCP or BootP.
subnet 192.168.1.0 netmask 255.255.255.0 {
range dynamic-bootp 192.168.1.32 192.168.1.254;
option broadcast-address 192.168.1.255;
option routers 192.168.1.1;
get-lease-hostnames true;
}
# On our .2 subnet we have a mixture of dynamically
# assigned addresses and a collection of hosts that
# should have fixed addresses.
subnet 192.168.2.0 netmask 255.255.255.0 {
range dynamic-bootp 192.168.2.32 192.168.2.254;
option broadcast-address 192.168.2.255;
option routers 192.168.2.1;
}
# Our fixed address hosts belong to a different
# name domain and should have names assigned to
# them in addition to addresses.
group {
option domain-name "apps.testnet.net";
use-host-decl-names on;
host guava {
hardware ethernet 08:00:00:1a:2b:3c;
fixed-address 192.168.2.16;
}
host nectarine {
hardware ethernet 08:00:00:3b:4f:fa;
fixed-address 192.168.2.17;
}
host banana {
hardware ethernet 08:00:02:01:55:cb;
fixed-address 192.168.2.18;
}
}
In our example we used only a small number of configurable parameters. If you're in a complex environment of mixed computer and operating system types, you will likely need more sophisticated configurations.
If you have any or many diskless workstations, you may need to build a somewhat more complex configuration. The following sample is what you might use if you had a collection of diskless X11 workstations. You can cluster the information that is common to all workstations together inside the group statement and then pass host-specific information in a host statement for each workstation. You can see that this sample passes a wider range of configuration data to the workstations including the addresses of time, font, display manager, printer, and NIS+ servers. Additionally the mango workstation is configured for IP routing and has a static route configured.
group {
# machine boot parameters
filename "/tftp/fruit.boot';
next-server guava.apps.testnet.net;
# application server parameters
option ntp-servers 192.168.1.32;
option x-display-manager 192.168.1.32, 192.168.2.32;
option font-servers 192.168.1.32, 192.168.2.32;
option lpr-servers 192.168.1.32;
option nisplus-domain testnet;
option nisplus-servers 192.168.1.32, 192.168.2.32;
# Workstation specific parameters
host mango {
hardware ethernet 08:00:02:30:02:ba;
fixed-address 192.168.2.19;
option ip-forwarding 1;
option static-routes 10.1.0.1 192.168.2.1;
}
host passionfruit {
hardware ethernet 08:00:a3:6c:0b:21;
fixed-address 192.168.2.20;
}
}
More detailed configuration information is available from the dhcpd.conf, dhcp.leases and dhcp-options man pages, and from the Internet Software Consortium web site.
Terry Dawson is the author of a number of network-related HOWTO documents for the Linux Documentation Project, a co-author of the 2nd edition of O'Reilly's Linux Network Administrators Guide, and is an active participant in a number of other Linux projects.
Read more Linux Network Administration columns.
Return to the Linux DevCenter.
Copyright © 2009 O'Reilly Media, Inc.