A simple DHCP server setup on RHEL Clones like WBEL, Centos, TaoLinuxThis
guide is how to setup a simple DHCP server to run on a RHEL Clone like
WBEL, Centos, TaoLinux. The guide is based on having at least a minimal
installation of one of the supported OSes. See this
guide to install a minimal version of a supported OS if required.
What is DHCP?DHCP
is an acronym that stands for "Dynamic Host Configuration Protocol".
DHCP's purpose is to enable individual computers on an IP network to
automatically obtain their network configurations from a server, instead
of requiring each PC's network configuration to be completed manually.
The overall purpose of this is to reduce the work necessary to
administer a large IP network. DHCP runs over UDP, utilizing ports 67
and 68.
How do I setup DHCP on a RHEL clone like White Box Enterprise Linux (WBEL), CentOS, or TaoLinux?1. Do the above mentioned
minimal install, if required.
2. After updating your linux install, install the programs required for the DHCP server with this command:
yum install dhcpImportant Files:To configure a DHCP server we will modify the configuration file
/etc/dhcpd.conf. DHCP also uses the file
/var/lib/dhcp/dhcpd.leases to store the client lease database.
Help for DHCPHelp is available from the following man pages:
man dhcp-eval
man dhcpd.conf
man dhcpd.leases
man dhcpd
man dhcrelay3.
Next we need to configure the DHCP server. First we need to know some
information that we are going to assign. We need to know:
a.
The range of IP addresses we want to assign to our computers. I
normally use the 192.168.x.x networks for my internal LANs. In our
example, we will use 192.168.0.0/255.255.255.0 as our network (that is
the network that starts with 192.168.0.1 and ends with 192.168.0.254).
We will save IPs 192.168.0.1 to 192.168.0.50 for servers and static
addresses. We will pick the addresses 192.168.0.51 to 192.168.0.100 to
assign to computers via DHCP.
b. The IP address of the DNS
server(s) we will use for name lookups for our clients that we assign
with DHCP. In my case, I will use the DNS server that I have setup on
IP address 192.168.0.2. (You can use your ISP's DNS server if you don't
have one ... see the ISP's site for details. You can also build your
own internal DNS server on this machine or another internal machine by
following
this guide.
c.
The Default Gateway of the computers that we are going to serve. In
our example, this will be the IP address 192.168.0.1, which has been
setup as the default gateway for our internal network.
d. The
length of the lease (default and maximum). This is very subjective. If
you have more PCs than IP addresses to give out, you want this to be a
short time (600 seconds). If you have more IPs to give out than PCs
(most likely the case), you can use a larger number. Microsoft defaults
to 3 days (259200 seconds) with their DHCP servers. RedHat recommends
12 hours (43200 seconds). I will go with the RedHat default of 43200
seconds for default length and 86400 seconds for maximum length.
e.
If we have a WINS server setup on the network (microsoft or samba
only), we would need to know it's IP address. I have one, it is
192.168.0.2 (on the same machine as my DNS server).
f. We need a
domain name to give out as well. If you are using real IP addresses,
you can use a real domain name as well ... in our case, we are using an
internal network (192.168.0.x) behind a single IP address from an ISP,
so we will use the fictitious domain name
home.local. If you are
using an internal IP network, don't use a real external domain name, or
you may not be able to talk to real PCs on that external network.
The DHCP Server configuration file (/etc/dhcpd.conf)1. Now we have our information, so let's configure the server by creating a text file named
/etc/dhcpd.conf. The first line in the file must be the
DNS update scheme. There are 2 choices, but only one that works reliably ... so we will use that one
. Here is the first line:
CODE
ddns-update-style interim;
2.
The second line is whether to allow the DHCP to update client info to a
Dynamic DNS server. In our example, we are not going to try and update a
Dynamic DNS via our DHCP server, so we will not allow client updates.
Here is our line 2:
CODE
ignore client-updates;
3.
The next section of our file will be the subnet section ... we will
define the network, and input the info we gathered above (see section 3
{a-f} above). Here is the subnet section:
CODE
subnet 192.168.0.0 netmask 255.255.255.0 {
option routers 192.168.0.1; #Default Gateway
option subnet-mask 255.255.255.0;
option domain-name "home.local";
option domain-name-servers 192.168.0.2;
option netbios-name-servers 192.168.0.2; #WINS Server
range dynamic-bootp 192.168.0.51 192.168.0.100; #DHCP Range to assign
default-lease-time 43200;
max-lease-time 86400;
}
4. Put all that together and we have the
/etc/dhcpd.conf file. Here is a text file containing our example information.
example dhcpd.conf5. If you have more than one ethernet adapter, you must specify which one to listen on in the file
/etc/sysconfig/dhcpd. To listen on
eth0, you would use the line:
CODE
DHCPDARGS=eth0
6. To start the dhcp server now for testing, issue the command:
/etc/init.d/dhcpd startTo make the dhcp server restart at boot time, issue the commands:
chkconfig --level 2345 dhcpd on
chkconfig --level 016 dhcpd offThen check to make sure it is correct with the command:
chkconfig --list dhcpdthe output should be
dhcpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off7.
If you are using a software firewall like iptables, you will need to
allow all tcp and udp traffic into ports 67 and 68 into this machine.
8. Here are some good references:
DHCP Server Setup (some paths are different, but still good info)
RHEL - Configuring a DHCP Server <--excellent br="br" reference="reference">
Using DHCP on Linux/FreeBSD <--info and="and" br="br" dhcp="dhcp" dns="dns" dynamic="dynamic" on="on">
TCP/IP Network Administration - DHCP
--info>--excellent>