FreeUnix.Dyndns.Org Sat, 21 November 2009 - 10:13:18 CET
Home ·  AcpiTool ·  Howto ? ·  Links ·  Hardware ·  FTP Archive ·  Search ·  Contact ·  About
>  Using DHCP on Linux/*BSD   <
Index
This article will explain how you can use DHCP on Linux and FreeBSD, covering both client and server side. It will thus tell you how to configure a client to use DHCP and how to install a DHCP server.
This article assumes you have at least some basic knowledge of TCP/IP networking and know how to configure a Linux distro and FreeBSD release. This document will only cover Slackware Linux since that's what the author is using and he is too lazy to cover all these other distro's. However, most of this document is applicable to every Linux distro.
And as always, you should know what you are doing.
What is DHCP ?
DHCP stands for Dynamic Host Configuration Protocol. It's used to provide clients with vital network information. It provides automated, managed configuration of computers and other devices using TCP/IP.
DHCP is built around a client-server model in which networked clients contact a central server to obtain configuration parameters. A DHCP server allows a network administrator to control the assignment of addresses and other TCP/IP protocol parameters. You can use fully dynamic address assigment, pre-assign a specific address to clients or use a mixed strategy.
DHCP allows you to add new clients, replace or move existing clients between networked locations without explicit intervention of users or a network administrator. Just connect it to the network and it should work.
DHCP internals
How can a client contact a DHCP server before it has a valid IP address ? DHCP uses UDP to deliver protocol messages. UDP has 2 specific features that are used by DHCP :
  • UDP messages can be broadcast to every host on a network segment rather than to just a single computer
  • UDP can transmit messages with a source IP address of 0.0.0.0 if the source computer has not yet been assigned an IP address.
These features allow a computer to use UDP to locate and communicate with a DHCP server before the computer has an IP address : DHCP uses the limited broadcast address, 255.255.255.255, as destination IP address and the "this host" address, 0.0.0.0, as the source IP address.
Sending a broadcast to 255.255.255.255 limits the delivery from a client to servers that are connected to the same network segment as the client. In a multi segmented environment, DHCP uses relay agents, often implemented in routers, to forward broadcast messages from clients to servers and back.

The client broadcasts if it does not have an IP address, but, if the client has an IP address of its own and knows the IP address of the DHCP server, it sends messages directly to the server. When transmitting DHCP messages, a client sends datagrams to UDP port 67 (Server port), and the server sends datagrams to UDP port 68 (Client port).

DHCP clients are said to be in a certain state :

  • If the client does not have an IP address, it's in state INIT
  • During initial configuration, it moves to SELECTING state
  • When it is successfully configured with an IP address, it's in BOUND state
  • When the client restarts, it goes to INIT - REBOOT, and after confirming its IP address is still valid, moves to BOUND. If the server denies the address, the client moves back to INIT.
  • Some time before the lease expires, the client enters the RENEWING state : it attempts to extend its lease. It this fails, it will enter REBINDING state and tries to extends its lease from any available server. If this fails too, it reverts to the INIT state.
DHCP messages
If the client is in INIT state and needs to obtain a lease, it finds a DHCP server by sending a broadcast DHCPDISCOVER message. This message is delivered to all DHCP servers on the same network segment as the client. It's also received by relay agents (if any) and forwarded to DHCP servers on other networks.

When the server receives a DHCPDISCOVER message from a client, it finds an address to assign to the client, and puts in in a DHCPOFFER message, together with other configuration parameters, defined by the server's configuration file. It then sends the message to the client.

When the client receives the DHCPOFFER message, it sends a DHCPREQUEST message to the server. In this message, the client asks for the address and other configuration parameters.

After receiving the DHCPREQUEST message from the client, the server checks the requested address and parameters to ensure the address is still available and the parameters are correct. It then records the assigned address and sends a DHCPACK message to the client.
When the client receives the DHCPACK message, it records the assigned information and configures its TCP/IP software with the received IP address and other parameters. The client can begin using TCP/IP.

Example #1: logged messages for a succesfull DHCP request (Linux based DHCP server, hostname is zeus):

zeus dhcpd: DHCPDISCOVER from 00:e0:00:5a:9c:ee via eth0
zeus dhcpd: DHCPOFFER on 192.168.1.99 to 00:e0:00:5a:9c:ee via eth0
zeus dhcpd: Wrote 24 leases to leases file.
zeus dhcpd: DHCPREQUEST for 192.168.1.99 (192.168.1.1) from 00:e0:00:5a:9c:ee via eth0
zeus dhcpd: DHCPACK on 192.168.1.99 to 00:e0:00:5a:9c:ee via eth0

Example #2: client that was previously connected to a different subnet receives a NAK and is offered a new IP

zeus dhcpd: DHCPREQUEST for 172.16.32.156 from 00:10:4b:e2:53:42 via eth0: wrong network.
zeus dhcpd: DHCPNAK on 172.16.32.156 to 00:10:4b:e2:53:42 via eth0
zeus dhcpd: DHCPDISCOVER from 00:10:4b:e2:53:42 via eth0
zeus dhcpd: DHCPOFFER on 192.168.1.98 to 00:10:4b:e2:53:42 via eth0
Previous Top Index Next