Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Network Services»DHCP»How to Configure DHCP Server on CentOS/RHEL 7/6/5

    How to Configure DHCP Server on CentOS/RHEL 7/6/5

    By RahulJuly 7, 20183 Mins Read

    DHCP (Dynamic Host Configuration Protocol) is a network protocol used for assigning IP address to network clients dynamically from a predefined IP pool. It is useful for LAN network, but not generally used for production servers. This article will help you for Configuring DHCP Server on CentOS, Red Hat System. Read more about dhcp here.

    Advertisement

    dhcp

    Install DHCP Package

    First install DHCP packages using yum package manager on CentOS, Red Hat systems. DHCP rpms are available under base repositories, so we don’t need to add an extra repository.

    yum install dhcp
    

    Update /etc/sysconfig/dhcpd File

    Firstly we need to set ethernet interface name as DHCPDARGS in /etc/sysconfig/dhcpd file. Edit this configuration file and update the ethernet name.

     DHCPDARGS=eth1
    

    Configure DHCP Server

    DHCP creates an empty configuration file /etc/dhcp/dhcpd.conf. Also it provides a sample configuration file at /usr/share/doc/dhcp*/dhcpd.conf.sample, which is very useful for configuring the DHCP server.

    So as a first part, copy the content of sample configuration file to the main configuration file. Sample configuration file may be changed as perversion you have installed on your system.

    # cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
    

    3.1 – Parameter Configuration

    First configure the basic options which is common to all supported networks.

      option domain-name "tecadmin.net";
      option domain-name-servers ns1.tecadmin.net, ns2.tecadmin.net;
      default-lease-time 600;
      max-lease-time 7200;
      authoritative;
      log-facility local7;
    

    3.2 – IP Subnet Declaration

    First, edit DHCP configuration file and update subnet details as per your network. For this example we are configuring DHCP for 192.168.1.0/24 LAN network.

    subnet 192.168.1.0 netmask 255.255.255.0 {
            option routers                  192.168.1.254;
            option subnet-mask              255.255.255.0;
            option domain-search            "tecadmin.net";
            option domain-name-servers      192.168.1.1;
            option time-offset              -18000;     # Eastern Standard Time
    	range   192.168.1.10   192.168.1.100;
    }
    

    3.3 -Assign Static IP Address to Host

    In some cases, we need to assign a fixed IP to an interface each time it requested from dhcp. We can also assign a fixed IP on basis of MAC address (hardware ethernet) of that interface. Setup host-name is optional to set up.

    host station1 {
       option host-name "station1.example.com";
       hardware ethernet 00:11:1A:2B:3C:AB;
       fixed-address 192.168.1.100;
    }
    

    Start DHCP Service

    After making all above changes, let’s start dhcp service using following commands as per your operating system version.

    For CentOS/RHEL 7
    systemctl start dhcp
    
    For CentOS/RHEL 6/5
    service dhcp start
    

    Similarly to stop and restart dhcp service use following commands.

    For CentOS/RHEL 7
    systemctl stop dhcp
    ystemctl restart dhcp
    
    For CentOS/RHEL 6/5
    service dhcp stop
    service dhcp restart
    

    Step 5: Setup Client System

    At this stage we have a running dhcp server which is ready for accepting requests and assign them a proper ip. but to verify I have another CentOS machine running on same LAN. Now login to that client machine and edit Ethernet configuration file.

    vim /etc/sysconfig/network-scripts/ifcfg-eth1
    
    DEVICE=eth1
    BOOTPROTO=dhcp
    TYPE=Ethernet
    ONBOOT=yes
    

    Make sure BOOTPROTO is set to dhcp.

    Let’s restart network services on the client machine. You will get that dhcp server assigned an ip address from the defined subnet. If you have connected to client pc from remote login, Your session can be disconnected.

    For CentOS/RHEL 7
    systemctl restart network
    
    For CentOS/RHEL 6/5
    service network restart
    

    DHCP host ip network
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    What is Localhost?

    Linux ip command with useful examples

    ip Command in Linux (Manage Networking)

    How to Install & Connect OpenVPN Client on Ubuntu

    View 12 Comments

    12 Comments

    1. widitya on September 18, 2022 2:38 am

      Hay Thank you for explained, but how to setup dhcp multi vlan ?

      Reply
    2. jason on February 26, 2021 5:45 pm

      Thanks for the dhcp setup. Had it working in minutes.

      Reply
    3. Musab on February 5, 2021 10:11 pm

      Thank you for this information

      Reply
    4. Nikhil Gaikwad on December 7, 2020 7:29 am

      very helpful, concept got cleared

      Reply
    5. Jamal on September 2, 2018 10:23 am

      Hello Rahul,

      Thank you very much for such a great information, I have a quesiton I’m working on a project at universtiy. I’m assigned to create a server client environment with CentOS server, I need to configure DNS, DHCP and LDAP. If you can please recommend any youtube channel or something else. At the moment scenario is, I have got 7 different subnets, each on a different VLAN, I want to configure dhcp scopes for those networks. I managed to configure the same on Windows 2012, because it is very simple and easy to configure by the help of dhcp scopes. but I have no idea how I am going to achieve the same on CentOS. Can you please help???

      Reply
    6. Contact Arlo support on July 19, 2018 12:18 am

      DHCP server is used to assigning the IP address to the clients. This process is used for the LAN network. For the production servers, DHCP is also used.

      Reply
    7. Mr Comp on November 11, 2017 7:16 am

      In centos/rhel 7.x the daemon should be dhcpd not dhcp.

      Reply
    8. Coen on April 4, 2017 10:36 am

      Just one notice, the command to copy the example configuration has a small mistake.

      # cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf

      should be example instead of sample (because it is an example).

      # cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.example /etc/dhcp/dhcpd.conf

      Nice tutorial, thanks a lot!

      Reply
    9. ABHISHEK NAYAK on November 11, 2016 8:43 am

      Good Knowledge and Also Give Step by Step Configuration,

      i want other details for Configuration like DNS, iSCSI, LDAP, TFTP etc…

      Reply
    10. Linus Torvalds on May 24, 2016 12:33 pm

      Yep, explained really well. All working!

      Reply
    11. ichiro on November 13, 2014 9:20 pm

      Well done, it works!!

      Reply
    12. Heta on July 29, 2014 2:42 am

      easy to understand website and quite helpful.

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Implementing a Linux Server Security Audit: Best Practices and Tools
    • cp Command in Linux (Copy Files Like a Pro)
    • 15 Practical Examples of dd Command in Linux
    • dd Command in Linux (Syntax, Options and Use Cases)
    • Iptables: Common Firewall Rules and Commands
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.