Вы находитесь на странице: 1из 7

Dynamic Host Configuration Protocol

One of the basics elements found on all networks is a Dynamic Host


Configura- tion Protocol (DHCP) server, making it an important part of any
network. DHCP makes network administration easy because you can make
changes to a single point (the DHCP server) on your network
it is an integral part of any network and a core functionality that every
network contains.
you need to know that the DHCP server listens on UDP port 67 for incoming
DHCP requests.
Before you can begin the installation or setup of a DHCP server, you need
to ver- ify that the server is configured with a static IP address. To verify
this, you can look at the interface config file:
# gedit /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE="eth0"
HWADDR="00:0C:29:0A:26:80"
NM_CONTROLLED="yes"
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.3.5
NETMASK=255.255.255.0
GATEWAY=192.168.3.1
DNS1=202.56.215.55
gedit /etc/sysconfig/network

NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=rdc.sushilsharma.com

Installing a DHCP Server


The DHCP server package is called dhcp, while the service is called dhcpd.
Step 1.

Start by installing the dhcp package:


# yum install -y dhcp

Step 2.

Verify that the package is installed correctly:


# rpm -qa | grep dhcp
dhcp-4.1.1-12.P1.el6.x86_64

Step 3.

With the package installed, make sure that the dhcpd service
starts when the system boots as well:
# chkconfig dhcpd on

Step 4.

Verify that the DHCP service starts on boot:


# chkconfig dhcpd --list
dhcpd
0:off
1:off
6:off

2:on

3:on

4:on

5:on

Configuring the DHCP Server


To start the configuration, lets look at the important files that handle the
options for the DHCP service:
/etc/dhcp/dhcpd.conf

Main config file for the DHCP service using IPv4 addresses

/etc/dhcp/dhcpd6.conf

Main config file for the DHCP service using IPv6 addresses

/var/lib/dhcpd/dhcpd.leases IPv4 client lease file


/var/lib/dhcpd/dhcpd6.leases IPv6 client lease file
MIGRATION TIP

In RHEL5, the location of the main config file was /etc/dhcpd.conf. Now
in RHEL6, the config file has been moved into a directory (/etc/dhcp)
because there are additional config files for IPv6 addresses.
To copy the sample file, use the following command:
# cp

/usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample

Here is the sample DHCP server config file:


# Global Options
ddns-update-style none;
authoritative;
# Subnet definition

/etc/dhcp/dhcpd.conf

subnet 172.168.1.0 netmask 255.255.255.0 {


# Parameters for the local subnet
option routers

172.168.1.1;

option subnet-mask

255.255.255.0;

option domain-name

example.com;

option domain-name-servers

172.168.1.1;

default-lease-time

21600;

max-lease-time

43200;

# Client IP range
range dynamic-bootp 172.168.1.100 172.168.1.200;
}

Lets break down this file into sections. The first section contains two
options for the DHCP server itself, also called global options:
ddns-update-style:
none
authoritative

This means that the DHCP server wont update client DNS
records.
This informs the client that the DHCP server contains
legitimate information.

The next section defines a subnet. Any options that you list in a subnet
section are specific to the subnet for which you define them. If you want
to set global options (such as authoritative), you need to define them
outside the subnet section. In this section, the following options are used:
option routers

Defines the default gateway to the

subnet
option subnet-mask

Defines the subnet mask for the

subnet
option domain-name

Defines the name of the domain

option domain-

Defines the DNS server for the subnet

name-servers

default-lease-time

Specifies how long each client keeps its lease until a renewal
is re- quested (in seconds)

max-lease-time

Specifies the maximum amount of time a client can keep a lease


(in seconds)

range dynamic-bootp

Specifies the range of IP addresses that can be given out to clients

Here are the three man pages you should know:


# man dhcpd.conf
# man dhcpd.leases
# man dhcp-options

Even though the DHCP server is set to run, there is another exam- ple to
consider. It is common in the real world to have to reserve an IP address
for a particular client. If you dont want to make the IP address of the client
static, you

can reserve it instead on the DHCP server.


Reservations are common when dealing with printers on networks, but
they can be used for clients, too. Here is how you define a reservation for a
client. In your /etc/dhcpd.conf file, do the following:
host client01 {

hardware ethernet 02:B4:7C:43:DD:FF;


fixed-address 172.168.1.50;

Again, lets look at each of these options and what they do.
hardware ethernet

Defines the MAC address of the client

fixed-address

Specifies the IP address that you want the client to receive

These three options are defined in a host subsection, just like you defined a
subnet section earlier. With the config files in place, you are now ready to
start the serv- ice. The DHCP server offers a particularly nice feature built
into the startup scripts; it can check the syntax of your config file for errors.
This capability is nice because prior to actually starting the service, you can
check to make sure nothing is set incorrectly.
Check the config file for any errors:
# service dhcpd configtest
Syntax: OK

If the DHCP service does find errors, it attempts to tell you where in the
config file the error exists. Open your config file and remove the brace (})
that ends the sub- net section. Save your config file and run the syntax
check on your config file again:
# service dhcpd configtest
Internet Systems Consortium DHCP Server V3.0.5-RedHat
Copyright 2004-2006 Internet Systems Consortium. All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/
/etc/dhcpd.conf line 18: unexpected end of file

^
Configuration file errors encountered exiting
Here, the service points out that the } is missing from the config file by giving
you the line where the issue occurs
as well as a general description of what the problem is. Now replace the }
again and restart the DHCP service:
# service dhcpd start
Starting dhcpd:

[ OK ]

Verify that the service is running:


# service dhcpd status
dhcpd (pid 3366) is running...

You should now have a fully functional DHCP server! You can boot up your
clients and see if they pick up an IP address,
or if the client is al- ready powered on, you can use the dhclient command to
request an IP address from the server.
Request a dynamic IP from the server:

# dhclient
Internet Systems Consortium DHCP Client V3.0.5-RedHat
Copyright 2004-2006 Internet Systems Consortium. All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/
Listening on LPF/eth0/08:00:27:74:5b:11
Sending on

LPF/eth0/08:00:27:74:5b:11

Sending on

Socket/fallback

DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 7


DHCPOFFER from 192.168.1.1
DHCPREQUEST on eth0 to 255.255.255.255 port 67
DHCPACK from 192.168.1.1
bound to 192.168.1.7 renewal in 40126 seconds.

Troubleshooting DHCP
Not all configurations go as smoothly as you might like. When youre troubleshooting the DHCP server, there
are a few things to watch out for. For example, in the main config file,
/etc/dhcp/dhcpd.conf, make sure that you
end all your options with a semicolon (;). If you dont, the service throws an
error when you check the config file.
For client troubleshooting, the DHCP server provides a client leases file. This
file contains all the lease information about each client that has
ob- tained an IP address from the server. When you have a client that has a
DHCP address, you can view the
leases file by using the following:
# cat /var/lib/dhcpd/dhcpd.leases
lease 172.168.1.200 {
starts 2 2010/05/11 12:24:10; ends
2010/05/11 18:24:10; binding state free;

2010/05/11 18:24:10; tstp 2

2010/05/20 17:24:03; tstp 4

hardware ethernet 08:00:27:74:5b:11;


}
lease 172.168.1.199 {
starts 4 2010/05/20 11:24:03; ends
2010/05/20 17:24:03; binding state free;
hardware ethernet 08:00:27:2f:80:8c;
}
As you can see from the file output, two clients have active leases. When
viewing the leases file
As a final tip, make sure you use the configtest option to test the syntax of
your config files before starting or restarting the service. This prevents any
errors from occurring when you try to start the service.

Вам также может понравиться