Using a DHCP Client
If your local network has a DHCP server, you can configure
Linux to obtain its IP address from this server automatically, by using a DHCP
client. This client sends a broadcast message on its local network segment to search
for a DHCP server. If a DHCP server responds, and if the ensuing negotiation is
successful, the result should be a system with an IP address and associated
information, fully configured to use the connection.
NOTE

If you want your computer to function as a DHCP server so
that it can deliver IP addresses to other systems, consult href="http:// /?xmlid=0-201-77423-2/ch05#ch05"> Chapter 5 , Configuring Other Computers via
DHCP. You''ll need to configure the DHCP server with a static IP address.
Most Linux distributions give you the option of using DHCP
during installation. You should be able to select a DHCP option when
configuring the network settings. If not, or if you need to reconfigure the
computer after installation, the easiest way to enable this feature is usually
to use a GUI configuration tool, such as Linuxconf (Red Hat or Mandrake), COAS
(Caldera), or YaST or YaST2 (SuSE). For instance, href="http:// /JVXSL.asp?x=1&mode=section&sortKey=insertDate&sortOrder=desc&view=&xmlid=0-201-77423-2/ch02lev1sec2&open=true&title=New%20This%20Week&catid=&s=1&b=1&f=1&t=1&c=1&u=1#ch02fig01#ch02fig01"> Figure 2.1 shows the YaST2 configuration
screen in which this option is set. Click Automatic Address Setup (via DHCP),
and the system will obtain its IP address via DHCP.
Figure 2.1. GUI configuration tools
make it easy to enable DHCP client operation.
easy. Potential problems include the following:
Incompatible DHCP clients Four
DHCP clients are common on Linux systems: pump ,
dhclient , dhcpxd , and dhcpcd (don''t confuse either of the latter two with dhcpd , the DHCP server). Although all four
work properly on many networks, some networks use DHCP servers that don''t get
along well with one or another Linux DHCP clients. You might therefore need to
replace your DHCP client package with another one.
Incompatible DHCP options DHCP
client options sometimes cause problems. In practice, this situation can be
difficult to distinguish from an incompatible DHCP client, but the solution is less
radical: You can edit the DHCP startup script to change its options.
Unfortunately, you''ll need to learn enough about your DHCP client to have some
idea of what options to edit. Reading the man page may give you some ideas.
Multi-NIC configurations If
your computer has two or more network interface cards (NICs), you may need to
get the DHCP client to obtain an IP address for only some cards, or to
disregard some information (such as the gateway address, described in more
detail shortly in "href="http:// /?xmlid=0-201-77423-2/ch02lev1sec3#ch02lev2sec3"> Adjusting the Routing Table ") for some
NICs. Again, editing the DHCP client startup script may be necessary, or you
may need to create a custom script to correct an automatic configuration after
the fact.
To help you make adjustments, href="http:// /JVXSL.asp?x=1&mode=section&sortKey=insertDate&sortOrder=desc&view=&xmlid=0-201-77423-2/ch02lev1sec2&open=true&title=New%20This%20Week&catid=&s=1&b=1&f=1&t=1&c=1&u=1#ch02table01#ch02table01"> Table 2.1 presents
the default DHCP client package, alternative DHCP client packages, locations of
DHCP startup scripts, and locations of closely related configuration files for
each of several popular Linux distributions. (Debian''s ifup tool,
unlike similarly named tools in other distributions, is a binary program with
the DHCP client package commands hard-coded, which can make modifying those
commands tricky. Some limited control can be exerted through the /etc/network/ interfaces configuration file.) Even if your distribution doesn''t officially
support your preferred DHCP client, you can install and use it. At worst,
you''ll need to modify the DHCP client startup script specified in href="http:// /JVXSL.asp?x=1&mode=section&sortKey=insertDate&sortOrder=desc&view=&xmlid=0-201-77423-2/ch02lev1sec2&open=true&title=New%20This%20Week&catid=&s=1&b=1&f=1&t=1&c=1&u=1#ch02table01#ch02table01"> Table 2.1 , or
create a custom DHCP client startup procedure by modifying some startup script
(precisely what script you might modify is partly dependent on your
distribution and partly a matter of personal preference).
Table 2.1. DHCP Client
Information for Seven Popular Linux Distributions
Distribution
Default DHCP Client
Alternative DHCP Clients
DHCP Client Startup Script
Extra Configuration Files
Caldera OpenLinux Server 3.1
dhclient
none
/etc/sysconfig/network-scripts/ifup-dhcp
etc/sysconfig/network , //etc/sysconfig/
network-scripts/ifcfg-eth0 , /etc/dhcp/dhclient.conf
Debian GNU/Linux 2.2
pump
dhcpcd
/sbin/ifup (binary file)
/etc/network/interfaces
Linux Mandrake 8.1
dhcpcd
dhclient , dhcpxd
/sbin/ifup
/etc/sysconfig/network , /etc/sysconfig/network-scripts/ifcfg-eth0
Red Hat Linux 7.2
pump
dhcpcd
/sbin/ifup
/etc/sysconfig/network , /etc/sysconfig/network-scripts/ifcfg-eth0
Slackware Linux 8.0
dhcpcd
none
/etc/rc.d/rc.inet1
none
SuSE Linux 7.3
dhcpcd
dhclient
/etc/init.d/dhclient
/etc/rc.config
TurboLinux 7
dhclient
none
/sbin/ifup
/etc/sysconfig/network , /etc/sysconfig/network-scripts/ifcfg-eth0
If you suspect you''re encountering problems because of DHCP
client options that don''t get along well with those of your network''s DHCP
server, you can try editing the DHCP startup script listed in href="http:// /JVXSL.asp?x=1&mode=section&sortKey=insertDate&sortOrder=desc&view=&xmlid=0-201-77423-2/ch02lev1sec2&open=true&title=New%20This%20Week&catid=&s=1&b=1&f=1&t=1&c=1&u=1#ch02table01#ch02table01"> Table 2.1 . Look for the line that calls the
DHCP client program and examine its options, using the man page for the DHCP
client program for reference. You may need to add or remove options to get the
behavior you need. For instance, some DHCP servers require that the client send
a hostname, so you may need to add an option like -h hostname
for dhcpcd . Sometimes these
scripts rely on values set in other configuration files, as listed in the Extra
Configuration Files column of href="http:// /JVXSL.asp?x=1&mode=section&sortKey=insertDate&sortOrder=desc&view=&xmlid=0-201-77423-2/ch02lev1sec2&open=true&title=New%20This%20Week&catid=&s=1&b=1&f=1&t=1&c=1&u=1#ch02table01#ch02table01"> Table 2.1 . More frequently, though, these
files tell the system whether to use a static IP address or DHCP.