DNS / NTP / DHCP Lab Server

Ever thought about running your own DNS, NTP and DHCP Server within your own home/office lab environment and for free? If you’re somewhat familiar with Linux (CentOS is being used here) and like to play with command line interfaces here’s a way to run all services on the Server.

The following will help guide you through prerequisites and how-to details in order to bring up the services and test whether they’re working or not.

Outline of setting up NTP, DNS-Bind9 and DHCPd

  • Prepare CentOS 7.3 Server
  • Install and configure NTP
  • Install and configure DNS-Bind9
  • Install and configure DHCPd

PrepareĀ CentOS 7.3 Server

login as root

Install net-tools (re: ifconfig)
yum -y install net-tools

Stop and disable NetworkManager:
systemctl stop NetworkManager
systemctl disable NetworkManager
systemctl start network
systemctl stop firewalld
systemctl disable firewalld

Edit /etc/selinux/config and change
vi /etc/selinux/config

SELINUX=disabled

update the system and reboot
rm -fr /var/cache/yum/*
yum clean all
yum update -y
reboot

Install and configure NTP

yum -y install ntp

Edit ntp.conf file pointing to which ever ntp pool of your choosing
vi /etc/ntp.conf
server 0.us.pool.ntp.org iburst
server 1.us.pool.ntp.org iburst
server 2.us.pool.ntp.org iburst

Add Local Clock as Backup to /etc/ntp.conf file

server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10

Enable NTP Logging

statsdir /var/log/ntpstats/

restart ntp service and check status
systemctl restart ntp
systemctl status ntp
ntpq -p

Speed up ntp sync
service ntpd stop
ntpdate -u 192.168.0.145
service ntpd start

Install and Configure DNS-Bind9

yum -y install bind bind-utils

configure the named file
vi /etc/named.conf

options {
listen-on port 53 { 127.0.0.1; any; };
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 { any; };

allow-query { any; };

zone "lab.local" {
type master;
file "forward.lab.local";
};

// add reverse lookup for zone 192.168.1
zone "1.168.192.in-addr.arpa" {
type master;
file "reverse.lab.local";
};

// add reverse lookup for zone 10.252.1
zone "1.252.10.in-addr.arpa" {
type master;
file "reverse.lab.local";
};

Edit the forward file
vi /var/named/forward.lab.local

$TTL 604800
@ IN SOA dns.lab.local. admin.lab.local. (
3 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL

; name servers - NS records
IN NS dns.lab.local.

; name servers - A records
dns.lab.local. IN A 10.162.1.186

; 10.162.1.32/27 - A records
vsd01.lab.local. IN A 10.162.1.34
vsd02.lab.local. IN A 10.162.1.35
vsd03.lab.local. IN A 10.162.1.36
; VSD Server list
xmpp.lab.local. IN A 10.162.1.34
xmpp.lab.local. IN A 10.162.1.35
xmpp.lab.local. IN A 10.162.1.36
; VSD XMPP Server list
_xmpp-client._tcp.xmpp.lab.local. IN SRV 10 0 5222 vsd01.lab.local.
_xmpp-client._tcp.xmpp.lab.local. IN SRV 10 0 5222 vsd02.lab.local.
_xmpp-client._tcp.xmpp.lab.local. IN SRV 10 0 5222 vsd03.lab.local.

; 10.162.0.0/24 - A records
vsc01.lab.local. IN A 10.162.0.25
vsc02.lab.local. IN A 10.162.0.26

Edit the reverse file
vi /var/named/reverse.rsof.accenture

$TTL 604800
@ IN SOA dns.lab.local. root.lab.local (
2011071001 ; Serial
3600 ; Refresh
1800 ; Retry
604800 ; Expire
86400 ; Minimum TTL
)
NS dns.lab.local.

$ORIGIN 1.162.10.in-addr.arpa.
$TTL 604800
34 PTR vsd01.lab.local.
35 PTR vsd02.lab.local.
36 PTR vsd03.lab.local.

$ORIGIN 0.162.10.in-addr.arpa.
$TTL 604800
10 PTR test.lab.local.

Start the Service and ensure it starts at boot
systemctl restart named
chkconfig named on

Run the following command to check the syntax of the named.conf files
(Forward lookup using FQDN)
dig +noall +an @10.162.1.186 vsd01.lab.local

Results:
vsd01.lab.local. 604800 IN A 10.162.1.34
——————-
(Reverse lookup using IP ADDR)
dig +noall +an @10.162.1.186 -x 10.162.0.21

Results:
34.1.162.10.in-addr.arpa. 604800 IN PTR vsd01.lab.local.
——————-
dig +noall +an @10.162.1.186 SRV _xmpp-client._tcp.xmpp.lab.local. lab.local
Results:
_xmpp-client._tcp.xmpp.lab.local. 604800 IN SRV 10 0 5222 vsd01.lab.local.
_xmpp-client._tcp.xmpp.lab.local. 604800 IN SRV 10 0 5222 vsd02.lab.local.
_xmpp-client._tcp.xmpp.lab.local. 604800 IN SRV 10 0 5222 vsd03.lab.local.

Install and Configure DHCPd

yum -y install dhcp

Edit the dhcpd.conf file
vi /etc/dhcp/dhcpd.conf

ddns-update-style interim;
option domain-name "lab.local";
option domain-name-servers dns.lab.local;
default-lease-time 600;
max-lease-time 7200;
authoritative;
log-facility local7;

# local network used to trasmit range
subnet 192.168.0.0 netmask 255.255.255.0 {}

subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.200 192.168.1.210;
option routers 192.168.1.1;
option broadcast-address 192.168.1.255;
option subnet-mask 255.255.255.0;
option ntp-servers 192.168.0.145;
option domain-name-servers 192.168.0.145;
allow unknown-clients;
}

subnet 10.162.1.0 netmask 255.255.255.0 {
range 10.162.1.200 10.162.1.210;
option routers 10.162.1.1;
option broadcast-address 10.162.1.255;
option subnet-mask 255.255.255.0;
option ntp-servers 192.168.0.145;
option domain-name-servers 192.168.0.145;
allow unknown-clients;
}

Start the Service and ensure it starts at boot
systemctl start dhcpd
systemctl enable dhcpd



Categories: network services

Tags: , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: