DHCP - Assigning IP addresses

DHCP, Dynamic Host Control Protocol, is a method for assigning IP addresses to hosts on a network. A DHCP server running on a network manages a pool of available IP addresses and doles them out to hosts that request them. This way, machines can be added to a network dynamically so if your buddy comes over with his shiny new laptop, he can hop on your LAN with ease. Otherwise, you must statically assign an IP address to each machine on your network. This probably easy to manage in a home network, but it can get annoying quickly

Every NIC card has a unique MAC (Media Access Control) ID number. When you plug a host into the network running a DHCP client, it sends a packet out on the network broadcast (255.255.255.255). In that packet, is a request for an IP and the NIC card's MAC ID. The DHCP server is configured to listen for these requests. When it receives one, it checks the pool of available IP addresses. It then leases an IP to the MAC ID, returning another broadcast packet out on the network. The DHCP client receives the acknowledgement and the packet contains data telling the host it's IP and generally your other routing information. The DHCP reply packets will usually handle the job of telling a host it's default route, it's DNS servers, and many other configurable pieces of information as well.

Lets take a look at a sample dhcpd.conf file:
#	$OpenBSD: dhcpd.conf,v 1.1 1998/08/19 04:25:45 form Exp $
#
# DHCP server options.
# See dhcpd.conf(5) and dhcpd(8) for more information.
#

# Network:		192.168.1.0/255.255.255.0
# Domain name:		my.domain
# Name servers:		192.168.1.3 and 192.168.1.5
# Default router:	192.168.1.1
# Addresses:		192.168.1.32 - 192.168.1.127
#
shared-network LOCAL-NET {
	option  domain-name "my.domain";
	option  domain-name-servers 192.168.1.3, 192.168.1.5;

	subnet 192.168.1.0 netmask 255.255.255.0 {
		option routers 192.168.1.1;

		range 192.168.1.32 192.168.1.127;
	}
}
This is pretty straightforward. It sets up a pool of dynamically assignable IPs from 192.168.1.32 to 192.168.1.127 inside of network 192.168.1.0/24 . Furthermore, it tells those machines that their default route is at 192.168.1.1, they have a domain name of "my.domain" and name servers at 192.168.1.3 and 192.168.1.5. The sample file reserves the first 30 IPs in 192.168.1.0/24 for static IP machines. You can also add entries to assign specific IPs to specific MAC addresses thus assuring certain machines get the same IP every time.

DHCP is infinitely configurable but the example above -- with appropriate entries for your local network should be sufficient for home network. The only caveat with DHCP is that you must have your network carefully segmented. You should not have two DHCP servers attempting to assign IPs on the same network segment. So if you have a DSL connection to the Internet, you need to have two IPs in one Linux box that connects to both the DSL router and the other to a hub connected to your internal LAN. The reason is that your Internet provider will also be attempting to assign IPs via DHCP and you will have problems if your network is not segmented this way.