Install and configure DHCP server on centos 6

Setup DHCP server on Centos 6 :

Dynamic Host Configuration Protocol (DHCP) is used to assign IP addresses and other stuff like gateway and DNS details automatically to the clients. we need a DHCP server configured for offering ipaddress to the clients when it is required .

Installing DHCP server on Centos 6:

After installing Centos 6 (Centos 6 installation step by step screenshots ) and configuring network (How to setup network in centos 6)

Update yum repositories and packages by typing the below command

[root@localhost ~]# yum update

Step 1 » Install dhcp server and client using the below command

[root@localhost ~]# yum install dhcp

Step 2 » After installing dhcp server packages along with dependencies .Assign a static ip (eg: “192.168.1.11”) in the same DHCP range for the listening interface ( eg : “eth0” ). Open /etc/sysconfig/network-scripts/ifcfg-eth0 file and make the changes as per your requirement .

DEVICE="eth0"
HWADDR="00:0C:29:F1:01:4B"
NM_CONTROLLED="yes"
ONBOOT="yes"
BOOTPROTO="none"
IPADDR=192.168.1.11
NETMASK=255.255.255.0
GATEWAY=192.168.1.1

Step 3 » Now open /etc/sysconfig/dhcpd file and add the preferred interface name to DHCPDARGS variable as below

# Command line options here
DHCPDARGS=eth0

Step 4 » open /etc/dhcp/dhcpd.conf file and paste the below lines and save it.

#specify domain name
option domain-name "krizna.com";
#specify DNS server ip and additional DNS server ip
option domain-name-servers 192.168.1.10, 208.67.222.222;
#specify default lease time
default-lease-time 600;
#specify Max lease time
max-lease-time 7200;
#specify log method
log-facility local7;
#Configuring subnet and iprange
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.50 192.168.1.254;
option broadcast-address 192.168.1.255;
#Default gateway ip
option routers 192.168.1.1;
}
#Fixed ip address based on MAC id
host Printer01 {
hardware ethernet 02:34:37:24:c0:a5;
fixed-address 192.168.1.55;
}

Step 5 » Now start the service

[root@localhost ~]# service dhcpd start

and type this below command to start dhcp service automatically while booting.

[root@localhost ~]# chkconfig --levels 235 dhcpd on

That’s it .Clients can get IP from DHCP server and Please ensure you don’t have any other dhcp servers in the same network ( Routers might have DHCP enabled ).

18 Comments

    • Hi luis,
      It just because of selinux . please disable selinux and reboot your machine and try again.

      #vim /etc/selinux/config
      find this line
      SELINUX=enforcing
      and replace with
      SELINUX=disabled

      and reboot your machine .

  1. I have installed and configured dhcp,exactly as told in this post but when I am starting dhcpd service it’s getting failed …..can u please help me …and I also have disabled the selinux….but problem is still persisting……

  2. I have installed and configured dhcp,exactly as told in this post but when I am starting dhcpd service it’s getting failed …..can u please help me …and I also have disabled the selinux….but problem is still persisting……

  3. I’m having an odd problem, it keeps telling me semicolon expected when I start the dhcpd service, but I’m sitting here looking at the semicolon in the config file. I’ve re-created a few times and the same thing happens, won’t allow me to start the service.

  4. I’m having an odd problem, it keeps telling me semicolon expected when I start the dhcpd service, but I’m sitting here looking at the semicolon in the config file. I’ve re-created a few times and the same thing happens, won’t allow me to start the service.

  5. I never needed to disable selinux on a fresh install of Centos 6.6, worked straight away after installing.

  6. the people that get “Fail” when restart the DHCP, delete the dhcpd and download and install again. I had that problem and i fixed that issue doing that. Later just backup the dhcp file in another folder. To download dhcp use this command: yum install dhcp
    and if you want to delete the dhcp folder use this command: yum remove dhcpd

Leave a Reply

Your email address will not be published.


*