VizagInfo.com Home | VizagInfo Mirror of LG


<< Prev  |  TOC  |  Front Page  |  Talkback  |  FAQ  |  Next >>
LINUX GAZETTE
...making Linux just a little more fun!
An Introduction to DHCP
By Dean Wilson

An Introduction to DHCP



VizagInfo.com Home | VizagInfo Mirror of LG


An Introduction to DHCP

DHCP stands for Dynamic Host Configuration Protocol. What it does is dynamically assign network settings from a server. In other words, instead of having to configure the parameters related to how your computer communicates with a network, it happens automatically.

Assigning an IP address dynamically is the most basic piece but there is a lot more. This includes the netmask, host name, domain name, gateway and name servers. In addition, it can supply other information such as a time server.

Many people are anti-DHCP because they only see it as a way that an ISP offers you an IP address that changes. This, of course, makes it difficult to advertise a server. On the other hand, DHCP can save you a lot of ongoing configuration work within your company or organization.

Besides the ISP-provided DHCP servers, they commonly exist in inexpensive router boxes. Netgeark, Linksys and other vendors offer these systems with multiple LAN ports, an 802.11b wireless interface or both. The Netgear RP114 is an example of the wired LAN only and the Linksys WAP11 of the 802.11b type. There are many other choices. The router box becomes the system the ISP knows about and all of your real computers hide behind this box.

Hide? Effectively, yes. What is visible to the public Internet is the router. The LAN has private IP addresses and uses Network Address Translation (NAT) to handle connections from the internal systems to the Internet. While this isn't really a firewall, NAT offers a basic level of protection.

Most routers in this class allow you to:

That is the basics of DHCP for Beginners. If all you are doing is trying to decide between using DHCP or a static IP address, this may be enough information. On the other hand, you could decide to run a DHCP server on a Linux system. In that case, there are more options.

Linux as a DHCP Server

Dhcpd from ISC is the most common DHCP server shipped with Linux systems. When started it takes its directions from a configuration file usually found at /etc/dhcpd.conf. Here is a sample configuration file:

# Sample configuration file for ISC dhcpd

# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

default-lease-time 600;
max-lease-time 7200;

# if you do not use dynamical DNS updates:
#
# this statement is needed by dhcpd-3 needs at least this statement.
# you have to delete it for dhcpd-2, because it does not know it.
#
# if you want to use dynamical DNS updates, you should first read
# read /usr/share/doc/packages/dhcp-server/DDNS-howto.txt
ddns-update-style none; ddns-updates off;


# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

# This is a very basic subnet declaration.

subnet 10.254.239.0 netmask 255.255.255.224 {
  range 10.254.239.10 10.254.239.20;
  option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
}

# A slightly different configuration for an internal subnet.
subnet 10.5.5.0 netmask 255.255.255.224 {
  range 10.5.5.26 10.5.5.30;
  option domain-name-servers ns1.internal.example.org;
  option domain-name "internal.example.org";
  option routers 10.5.5.1;
  option broadcast-address 10.5.5.31;
  default-lease-time 600;
  max-lease-time 7200;
}

# Hosts which require special configuration options can be listed in
# host statements.   If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration.

host passacaglia {
  hardware ethernet 0:0:c0:5d:bd:95;
  filename "vmunix.passacaglia";
  server-name "toccata.fugue.com";
}

# Fixed IP addresses can also be specified for hosts.   These addresses
# should not also be listed as being available for dynamic assignment.
# Hosts for which fixed IP addresses have been specified can boot using
# BOOTP or DHCP.   Hosts for which no fixed address is specified can only
# be booted with DHCP, unless there is an address range on the subnet
# to which a BOOTP client is connected which has the dynamic-bootp flag
# set.
host fantasia {
  hardware ethernet 08:00:07:26:c0:a5;
  fixed-address fantasia.fugue.com;
}

The man page associated with this file, dhcpd.conf(5) is very thorough and I am not going to attempt to reproduce all that information here. Simply typing man dhcpd.conf will display it. It is over 25 printed pages but, should you want to print it for off-line study, the following commands should suffice:

cd /usr/share/man/man5
zcat dhcpd.conf.5.gz | groff -man | lpr

The file is divided into two types of statements. Parameter statements say how to do something of it dhcpd should do something. Declaraction statements describe the network. Thus, parameters establish things which declaractions may depend upon. In the example above default-lease-time is an example of a parameter. The block beginning with host fantasia { is a declaration. The option statements appearing outside of any block are global parameters which are global in scope. Those within declarations have a local scope.

I hope this introduction will help you work with DHCP. Being a DHCP client is very easy. On the server side it is not really complicated. Once you decide what you want your DHCP server to do, translating that information into what is needed in /etc/dhcpd.conf is a simple process.

Robert Wilson is a Systems Administrator in a company where the boss (who has no idea what Bob does) just says "make it work".


Unless otherwise mentioned, this work copyright © 2003-2004 by SSC, Inc. All rights reserved.

 

[BIO] Dean Wilson is (this week) a systems administrator and occasional updater to his pages at www.unixdaemon.net


Copyright © 2004, Dean Wilson. Copying license http://www.linuxgazette.com/copying.html
Published in Issue 98 of Linux Gazette, January 2004

<< Prev  |  TOC  |  Front Page  |  Talkback  |  FAQ  |  Next >>