How To Configure DHCP Server On CentOS

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

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

DHCP ( Dynamic Host Configuration Protocol ) is a network protocol used for assigning IP address to network
clients dynamically from 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.

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 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 content of sample configuration file to main configuration file. Sample configuration file
may be changed as per version 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

# systemctl 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 client system. You will get that dhcp server assigned an ip address from
defined subnet. If you have connected to client pc from remote login, Your session can be disconnect.

For CentOS/RHEL 7

# systemctl restart network

For CentOS/RHEL 6/5

# service network restart


How to Setup DNS (Bind) Server on CentOS/RHEL 7/6/5
The DNS (Domain Name System) is a distributed system, used for translate domain names to IP address and
vice a versa.For example when we type domain name in browser url like “http://tecadmin.net”, Our computer
sends a request to DNS and get an ip address of domain.
This article will help you to step by step setup dns server on CentOS and RedHat systems.

Network Scenario:
 DNS Server IP: 192.168.1.254
 DNS Server Name: ns1.tecadmin.net, ns2.tecadmin.net
 Domain Name: demotecadmin.net
 Domain IP to point: 192.168.1.100

Step 1 – Install Bind Packages


Bind packages are available under default yum repositories. To install packages simple execute below
command.

# yum install bind bind-chroot

Step 2 – Edit Main Configuration File


Default bind main configuration file is located under /etc directory. But using chroot environment this file is
located at /var/named/chroot/etc directory. Now edit main configuration file and update content as below.

# vim /var/named/chroot/etc/named.conf

Content for the named.conf file

// /var/named/chroot/etc/named.conf

options {

listen-on port 53 { 127.0.0.1; 192.168.1.0/24; 0.0.0.0/0; };

listen-on-v6 port 53 { ::1; };

directory "/var/named";

dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";

memstatistics-file "/var/named/data/named_mem_stats.txt";

allow-query { localhost; 192.168.1.0/24; 0.0.0.0/0; };

recursion yes;

dnssec-enable yes;

dnssec-validation yes;

dnssec-lookaside auto;

/* Path to ISC DLV key */

bindkeys-file "/etc/named.iscdlv.key";

managed-keys-directory "/var/named/dynamic";

};

logging {

channel default_debug {

file "data/named.run";

severity dynamic;

};

};
zone "." IN {

type hint;

file "named.ca";

};

zone "demotecadmin.net" IN {

type master;

file "/var/named/demotecadmin.net.db";

};

include "/etc/named.rfc1912.zones";

include "/etc/named.root.key";

Step 3 – Create Zone File for Your Domain


After creating bind main configuration file, create a zone file for you domain as per configuration, for
example demotecadmin.net.db in this article.

# vim /var/named/chroot/var/named/demotecadmin.net.db

Content for the zone file

; Zone file for demotecadmin.net

$TTL 14400

@ 86400 IN SOA ns1.tecadmin.net. webmaster.tecadmin.net. (

3013040200 ; serial, todays date+todays

86400 ; refresh, seconds


7200 ; retry, seconds

3600000 ; expire, seconds

86400 ; minimum, seconds

demotecadmin.net. 86400 IN NS ns1.tecadmin.net.

demotecadmin.net. 86400 IN NS ns2.tecadmin.net.

demotecadmin.net. IN A 192.168.1.100

demotecadmin.net. IN MX 0 mail.demotecadmin.net.

mail IN CNAME demotecadmin.net.

www IN CNAME demotecadmin.net.

If you are having more domain, its required to create zone files for each domain individually.

Step 4 – Add More Domains


To add more domains in dns, create zone files individually for all domain as above. After that add any entry for
all zones in named.conf like below. Change demotecadmin.net with your domain name.
zone "demotecadmin.net" IN {

type master;

file "/var/named/demotecadmin.net.db";

};

Step 5 – Start Bind Service


Start named (bind) service using following command.

# service named restart


Enable auto start on system boot.

# chkconfig named on

Step 6 – Test Your DNS Setup


Send query to your dns server directly using below command.
Syntax: nslookup <domainname> <dns server name/ip>

# nslookup demotecadmin.net 192.168.1.254

Server: 192.168.1.254

Address: 192.168.1.254#53

Name: demotecadmin.net

Address: 192.168.1.100

Above output is showing that dns server has successfully resolved domain demotecadmin.net.

You might also like