How-to : Basic PXE infrastructure #2 – DHCP server installation and setup on CentOS

pxe

Introduction

This is the second post from the How-to build a basic PXE infrastructure series, in which we are going to setup the DHCP server. The DHCP server will gives out the client IP address as well as the TFTP server IP address from which we can download the pxelinux.0 file.

This is the easiest part of the whole process,  at least in this context where we do not need extra DHCP functionality.

Reminder : The goal of this series is, again, to setup a minimalist working PXE infrastructure, we will see an advanced setup that uses kickstart and complex automated installation later, let’s start by the beginning !

 

 

The other post from this series

 

 

1) Install the dhcp server

Easy… launch the following command :

 yum install dhcp

In my case this installed this package

[root@CentOS-62_PXE-BASE ~]# rpm -q dhcp
dhcp-4.1.1-31.0.1.P1.el6.centos.1.x86_64

Let’s set it up to automatically start on boot :

chkconfig dhcpd on

Now we just need to edit the corresponding configuration file…

 

 

2) Edit the dhcpd.conf

Here is the dhcpd.conf (/etc/dhcp/dhcpd.conf) i used for the pxe setup, i commented some lines so you should be able to understand it, if you need more info please use the comment section.

#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample
#   see 'man 5 dhcpd.conf'
#
# dhcpd.conf for PXE service
# This is a very minimalist dhcpd.conf file, as it is only attended to use for PXE server.

subnet 192.168.30.0 netmask 255.255.255.0 {
        allow booting;
        allow bootp;
        # The following may be required if there is some other dhcp server in your LAN
        authoritative;
        option subnet-mask 255.255.255.0;

        # next-server gives the address of the tftp/pxe server (the local server in our case)
        next-server 192.168.30.222;
        ddns-update-style none;
        # This your (or any other, in this case i used the google dns) dns server
        option domain-name-servers      8.8.8.8;

        # This is your gateway, this information will be used by the dhcp client to setup its own network-setup
        option routers                  192.168.30.200;

        # This is the broadcast address
        option broadcast-address        192.168.30.255;

        # This is the default lease time in second (1 hour here)
        default-lease-time              3600;

        # This is used to restrict the number of lease for each dhcp client
        one-lease-per-client            false;

        # This specifies the addresses range that can be served by the dhcp server
        range                           192.168.30.15 192.168.30.30;

        # This is the pxe file to be used by the client
        # please note that the path to this filename will be search using the tftp server root
        # which is set in /etc/xinet.d/tftp @ server_args
        filename                        "pxelinux.0" ;
}

This file worked for me, i hope you will be as lucky as me! Ask in the comment section in case you are facing any problem.

Start the dhcp server :

service dhcpd start

You may test your new dhcp server using any computer configured to get dynamic  ip address, a virtual machine maybe ?

 

 

3) Debug you dhcp server

The setup is easy and should work without any problem, BUT in case you have forgot something (such as a semi-colon) here are some tips to ease the debugging.

3.1 dhcpd logs

The dhcp server spit inside the /var/log/messages file. A simple tail -f on this file while you are restarting a client network interface may gives you some good information about what’s going on.

3.2 Check the dhcpd.conf syntax

Errors that prevent the dhcpd service to start are mostly syntax error, hopefully there is an option that comes with the dhcpd init script that allow you to test your configuration file syntax :

/etc/init.d/dhcpd configtest

In case you made a typo or forgot a semi-colon you will see something like :

[root@CentOS-62_PXE-BASE ~]# service dhcpd configtest
Internet Systems Consortium DHCP Server 4.1.1-P1
Copyright 2004-2010 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
/etc/dhcp/dhcpd.conf line 11: expecting allow/deny key
        allow bootop;
               ^
/etc/dhcp/dhcpd.conf line 11: expecting a parameter or declaration
        allow bootop;
                     ^
Configuration file errors encountered -- exiting

This version of ISC DHCP is based on the release available
on ftp.isc.org.  Features have been added and other changes
have been made to the base software release in order to make
it work better with this distribution.

Please report for this software via the CentOS Bugs Database:
    http://bugs.centos.org/

exiting.
[root@CentOS-62_PXE-BASE ~]#

It is then quite easy to fix the problem. Please note that you should see the exact same debug message inside /var/log/messages.

Your dhcp client may still not get the expected address, this can be the case when you are testing in an environment with a pre-existent dhcp server.

In this case you may need to use the authoritative (see the line #14 in the dhcpd.conf above) declaration in order to be sure your client will get an address from YOUR dhcp server.

 

4) Conclusion

You may now have a working dhcp server, so let’s jump to the next step : tftp server.

 

More “How-to” posts

Tagged on: , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site supports SyntaxHighlighter via WP SyntaxHighlighter. It can highlight your code.
How to highlight your code: Paste your code in the comment form, select it and then click the language link button below. This will wrap your code in a <pre> tag and format it when submitted.