Industry guru Dave Taylor answers free tech support questions about a wide variety of business and technical topics, including blogging, Google AdSense, MySpace, Sony PSP, Apple iPod, Mp3 players, management, Linux, SEO, Mac OS X, Facebook, Twitter, LinkedIn and Microsoft Windows.

How do I install DHCP on my Linux Server?

I am planning to install DHCP on my Linux Server. I do not know that much in Linux (Red Hat), however. How can I install and configure a DHCP server on my system?


Dave's Answer:

First off, a definition. DHCP is the Dynamic Host Configuration Protocol and rather than use the default DHCP server included with your Red Hat / Fedora Linux system, I recommend that you pop over to the Internet Software Consortium and Download the latest version of the DHCP Server. As I write this, it's at version 3.0.3.

Why is it important to have the latest version? In a word, security. As with any software that you're going to run on your server, it's critically important that you have the very latest version of this 'daemon' (as we Linux geeks call programs that run on the server without intervention) on your system. It's also very important to shut off any services you aren't using (a process I detail in my popular book Teach Yourself Unix System Administration in 24 Hours, by the way).

So once you've downloaded the latest version of the software, you'll want to unpack it with:

$ tar xzf ./dhcp-303-tar.gz

Now, move to the new directory that contains all the source and type in the following commands (the tons of output these commands have has been deleted to save our sanity here):

$ ./configure
$ make

Assuming all has gone well, switch to root by using the sudo command and install the new server:

$ sudo make install

you'll be prompted for the root password, then, if you typed it in correctly, the new DHCP server will be installed onto your system.

Good. Now you have the latest DHCP server it's time to configure it properly for your environment. This is best done by copying the file server/dhcp.conf from the installation directory into your /etc directory, like this:

$ sudo cp server/dhcp.conf /etc

This time, since you just did a sudo command a few seconds ago, you won't be prompted for your password (an exceedingly slick feature of sudo, actually!)

Now, again using sudo, it's time to edit the configuration file to match your system configuration. Here's what the dhcp.conf file looks like:

ddns-update-style interim # Redhat Version 8.0+

subnet 192.168.1.0 netmask 255.255.255.0 {

# The range of IP addresses the server will issue to
# DHCP enabled PC clients booting up on the network

range 192.168.1.201 192.168.1.220;

# Set the amount of time in seconds that
# a client may keep the IP address

default-lease-time 86400;
max-lease-time 86400;

# Set the default gateway to be used by
# the PC clients

option routers 192.168.1.1;

# Don't forward DHCP requests from this NIC interface
# to any other NIC interfaces

option ip-forwarding off;

# Set the broadcast address and subnet mask
# to be used by the DHCP clients

option broadcast-address 192.168.1.255;
option subnet-mask 255.255.255.0;

# Set the DNS server to be used by the
# DHCP clients

option domain-name-servers 192.168.1.100;

# Set the NTP server to be used by the
# DHCP clients

option nntp-server 192.168.1.100;

# If you specify a WINS server for your Windows clients,
# you need to include the following option in the dhcpd.conf file:

option netbios-name-servers 192.168.1.100;

}

# List an unused interface here
#
subnet 192.168.2.0 netmask 255.255.255.0 {
}

# You can also assign specific IP addresses based on the clients'
# ethernet MAC address as follows (Host's name is "smallfry":

host smallfry {
hardware ethernet 08:00:2b:4c:59:23;
fixed-address 192.168.1.222;
}

As with many Linux configuration files, this is actually fairly well documented, especially since you should be able to type man dhcp-options to get an exhaustive explanation of each and every configuration option.

In particular, make sure you set the domain name properly, identify your set of DNS servers by name, and define the subnet range for which you want to provide services via DHCP.

Once that's all configured to your liking, a little bit more tweaking is required to get everything checked and started properly:

$ sudo touch /var/lib/dhcp/dhcp.leases

Will make sure that you have a 'leases' file, a critical part of how the DHCP server tracks what systems it's seen and serviced.

$ sudo chkconfig --level 35 dhcpd on

This will check your configuration and make sure it will be added to the list of daemons to start up at boot time from now on. Very useful if you don't want to remember to restart it each time!

$ /etc/init.d/dhcp restart

Now you should be running a DHCP server on your system. Check to make sure it's running by using ps aux | grep dhcp but you should be -- hopefully -- good to go!



Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

Comments

unless you really need to flexibility and power of a true blue dhcp server, try udhcpd. just google for it. its small and fairly stable for what its built for.

kjteoh

Posted by: kjteoh at February 7, 2006 4:57 AM

I want to know whether dhcp works across VLAN.
Or in each VLAN , we need to install individual DHCP Server.

Posted by: jagannath ojha at February 28, 2006 3:32 AM

We're getting a bit out of my depths, but as far as I understand, you'd need a different DHCP server on each LAN segment.

Posted by: Dave Taylor at February 28, 2006 9:03 AM

You don't need a DHCP server per VLAN. You will need to configure the L3 switch or router to forward IP broadcasts - Cisco uses IP helper command. When the router forwards the DHCP request it will "tell" the DHCP server from which subnet the request came. Your DHCP will then (if it supports it) allocate an appropriate IP address (ie one from that subnet). Some DHCP servers will only allocate addresses from their own subnet (in which case it won't work).

Posted by: Steve Worrall at May 31, 2006 4:05 PM

For different vlans how can i set up my dhcp server so that my client in diff.vlans get ip from dhcp server.
Any one help me
i am highly appreciated.

Posted by: Ganesh rout at May 7, 2007 3:23 AM

hello Suport, now i have dhcp server but that is very old now i want migrate this in new one , please guide me how can i take the backup of old ane restor same in new also let me know what configuration is require for dhcp installation in linux box.

Posted by: suneel at July 2, 2007 6:49 AM

i have downloaded the .tar, unpacked it, ./configure-make, are the commands i have done so far. but i have this lines after the make command

cc -g -I/root/dhcp-3.0.6 -I/root/dhcp-3.0.6/includes -DLINUX_MAJOR=2 -DLINUX_MINOR=4 -c -o raw.o raw.c
make[2]: cc: Command not found
make[2]: *** [raw.o] Error 127
make[2]: Leaving directory `/root/dhcp-3.0.6/work.linux-2.2/common'
make[1]: *** [all] Error 1
make[1]: Leaving directory `/root/dhcp-3.0.6/work.linux-2.2'
make: *** [all] Error 2

Posted by: osahon at November 20, 2007 10:17 AM

In version 3.0.6 you must issue the commands at the top of this page in this order. (3 seperate commands)

./configure
make
make install

Then continue like normal ...

Posted by: Ben DeMott at November 20, 2007 11:32 PM

i have a Intel P4 Pc with 945/946 intel motherboard and SATA HDD. How I can install RHEL 4 or Fedora core 5. How I can creat VPN, DHCP, DNS server in RHEL4/Fedora core 5.

Posted by: titas at December 4, 2007 8:16 AM

Where do i find the DHCp after its installed?

Posted by: Student at January 7, 2008 7:50 AM

I saw the post above that gets an error after make but can't find the resolution.
I do ./configure, then make and get the error, and get the same error after make install:
[root@server2 dhcp-3.0.3]# sudo make install
make[1]: Entering directory `/root/dhcp-3.0.3/work.linux-2.2'
Installing in common
make[2]: Entering directory `/root/dhcp-3.0.3/work.linux-2.2/common'
cc -g -I/root/dhcp-3.0.3 -I/root/dhcp-3.0.3/includes -DLINUX_MAJOR=2 -DLINUX_MINOR=6 -c -o raw.o raw.c
make[2]: cc: Command not found
make[2]: *** [raw.o] Error 127
make[2]: Leaving directory `/root/dhcp-3.0.3/work.linux-2.2/common'
make[1]: *** [install] Error 1
make[1]: Leaving directory `/root/dhcp-3.0.3/work.linux-2.2'
make: *** [install] Error 2

Posted by: jay at February 5, 2008 7:30 PM

it worked after i installed the gcc compiler.

Posted by: jay at February 6, 2008 5:29 PM

a litle tutorial to how to configure DHCP

dhcp

Posted by: Daniel at April 8, 2008 1:26 PM

The error output is from make - it means that a compiler - 'cc' - isn't in your path. So installing gcc will fix this.

You can check compilation/setup options by entering

./configure --help

before actually configuring the package. If you for example want to install it somewhere other than /usr/local you need to set it in the configure line like so

./configure --prefix=/folder/to/install/into


If running some other unix rather than linux be sure to install and use gnu 'make' rather than the system supplied one (the same goes for 'tar')

Posted by: John O'Driscoll at May 2, 2008 5:58 PM

I have a lot to say, but ...
Starbucks coffee cup I have a lot to say, and questions of my own for that matter, but most of all I'd like to say thank you for all your efforts on this Web site by buying you a chai!

I do have a comment, now that you mention it!









Remember personal info?


Please note that I will never send you any unsolicited commercial email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.


Help!





Subscribe to
Ask Dave Taylor!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Join the List!
Join my author info mailing list, where you'll learn about my upcoming books, speaking gigs, and more!


Book Links
© 2002 - 2008 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]