Quantcast
Username/Email:  Password: 

An Introduction to DHCP

Confused about what DHCP offers and how you can take advantage of it on your Linux system? Here are some tips and pointers.


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 to DHCP. This includes the netmask, host name, domain name, gateway
and name servers. In addition, DHCP can supply other information such as a
time server.

Many people are anti-DHCP, because they 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. Netgear, 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 a wired LAN, while the
Linksys WAP11 is an 802.11b type. Many other product choices are
available. When you use one, the router box becomes the system that
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. Although this isn't really a firewall, NAT offers a basic level
of protection.

Most routers in this class allow you to:

  • Clone the MAC (hardware) address of one of your computers. This
    allows you to make the ISP think it is talking to a computer
    system you previously identified rather than to a router with
    possibly multiple machines connected to it.
  • Handle static IP addresses. This means you could pick a local
    network address (192.168.1.x, for example) and assign specific
    addresses in this range.
  • Dynamically assign IP addresses from a specified range. For
    example, the router could be configured to offer DHCP for 20
    different addresses, say 192.168.1.100 thru 192.168.1.119.

That is the basics of "DHCP for Beginners". If you simply are 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 quite thorough,
and I am not going to attempt to reproduce all that information here.
Simply typing man dhcpd.conf| will display it. It
runs 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 dhcpd should do something. Declaration statements describe the network.
Thus, parameters establish things that declarations 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, meaning they are global in scope. Those
within declarations have a local scope.

I hope this introduction helps you work with DHCP. Being a DHCP
client is easy, and it is not really complicated on the server side
either. 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.

Copyright (c) 2004, Dean Wilson. Originally published in Linux
Gazette issue 98. Copyright (c) 2004, Specialized Systems Consultants,
Inc.

Dean Wilson is a system administrator and occasional
updater of his Web
pages
.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

deny users that did not acquire ip from the dhcp server?

Saritha's picture

how do i deny users that did not acquire ip from the dhcp server?

Debian dhcp server setup

Anonymous's picture

if you want to configure your debian server for dhcp very good and nice tutorial here

http://www.debianhelp.co.uk/dhcp.htm

Post new comment

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <i> <b>
  • Lines and paragraphs break automatically.
  • Use to create page breaks.

More information about formatting options