Configure DNS, DHCP and WebServer in Linux

TDhendup
0
A. Domain Name System

 

Ever thought if we are to remember IP (Internet Protocol) Addresses than the hostname/website name?  Imagine the trouble if the internet users should keep the IP addresses of the website (such as 192.0.1.2) instead of the website/hostname name (such as www.facebook.com). 

For example, imagine your Citizenship Identity Card (CID) number assigned to each of the citizens of the country. They are unique. So is the IP address of any website unique. In addition, imagine you calling a person through the use of CID number instead of the name. Shouldn't this be tiresome? Can you remember the CID number of all your staffs, friends, classmates, etc? 

What is a DNS (Domain Name System)? DNS helps people to map the hostname/website name to a corresponding IP address. 

Lets' configure a DNS in the Linux. 

In our tutorial, we will use BIND (Berkeley Internet Name Domain) as this is one of the most popular DNS package in use today. 

In our example, lets say your IP 192.168.1.13 should be configured as the DNS
IPADDR in ifcfg-eth0 is 192.168.1.13

# vi /etc/resolv.conf
nameserver 192.168.1.13

# vi /etc/hosts
192.168.1.13 lab1.com lab1

# vi /etc/sysconfig/network
HOSTNAME=lab1.com

# yum  -y install bind bind-utils bind-libs bind-chroot

# vi /var/named/chroot/etc/named.conf
options {
    directory "/var/named/";
};

zone "lab1.com" IN {
    type master;
    file "lab1.com.zone";
    allow-transfer { localhost;  192.168.1.2;  };
};

zone "1.168.192.in-addr.arpa"
    {
    type master;
    file "lab1.reverse.zone";
};

Now create the zone files  under /var/named/chroot/var/named
----------------------------------------------
# vi lab1.com.zone
$TTL 900
@    SOA    lab1.com.    root.lab1.com. (
                        2023073100 ;Serial
                        21600 ;Refresh for slave servers
                        1800; Retry for slave servers
                        60480;Expiry limit for cache on slave
                        900 ); Min cache TTL in zone records
@    IN    NS    ns.tshering.com.

;Host definition
www    IN    A    192.168.1.3
ns        IN    A    192.168.1.13
mail        IN    CNAME    ns

Also create the reverse.lab1.com
------------------------------------------------------------------
$TTL 900
@    SOA    tshering.com.    root.tshering.com.    (
                            
2023073100 ;Serial
                        21600 ;Refresh for slave servers
                        1800; Retry for slave servers
                        60480;Expiry limit for cache on slave
                        900 ); Min cache TTL in zone records
@        IN    NS    ns.tshering.com.

;PTR records

2    IN    PTR     www.tshering.com.
2    IN    PTR        mail.tshering.com.


-------------------------------------------------
Restart the named service and check for the errors
--------------------------------------------------

#/etc/init.d/named start

# more /var/log/messages | grep 'named'

If the cofiguration is seen error free, you should be able to lookup the following queries. Let us see if our DNS is working

#nslookup www.tshering.com
# dig -t NS tshering.com
# ping www.tshering.com
# dig @192.168.1.13 tshering.com
or
# dig @192.168.1.13  www.tshering.com


A. Dynamic Host Control Protocol (DHCP)
 
Imagine the means through which the devices connected to the wireless network of your office get access to internet. Imagine, suddenly you are given a set of devices to be connected to the network and have to assign them the individual IP addresses. Shouldn't this be the pain? Thus, DHCP automatically assigns the IP addresses to the devices instead of configuring the 'static' addresses (unless specifically required) to all the devices. 
 
To configure DHCP server in Linux, we are assuming two flavors of Linux and different flavors of linux has their path to the existing file viz., dhcpd.conf and dhcp3-server.
For Red Hat/CentOS/Fedora, the file is located under /etc/dhcpd.conf
For Ubuntu/Debian, the file is located under /etc/default/dhcp3-server
#vi /etc/dhcpd.conf or #vi /etc/default/dhcp3-server
 
NOTE: Please take the backup of the file before making any changes.


        ddns-update-style interim;                                  
        ignore client-updates;
        
        subnet 192.168.1.0 netmask 255.255.255.0 {
        
                range 192.168.1.128 192.168.1.254;                   # Range of IP addresses to be issued to DHCP clients
                   option subnet-mask              255.255.255.0;    # Default subnet mask to be used by DHCP clients
                   option broadcast-address        192.168.1.255;    # Default broadcastaddress to be used by DHCP clients
                   option routers                  192.168.1.1;      # Default gateway to be used by DHCP clients
                   option domain-name              "your-domain.org";
                   option domain-name-servers      40.175.42.254, 40.175.42.253;           # Default DNS to be used by DHCP clients
                   
        
        #         DHCP requests are not forwarded. Applies when there is more than one ethernet device and forwarding is configured.
        #       option ipforwarding off;
        
                default-lease-time 21600;                            # Amount of time in seconds that a client may keep the IP address
                max-lease-time 43200;
        
                
        #       option ntp-servers              192.168.1.1;         # Default NTP server to be used by DHCP clients
                
                # We want the nameserver "ns2" to appear at a fixed address.
                # Name server with this specified MAC address will recieve this IP.
        
                host ns2 {
                        next-server ns2.your-domain.com;
                        hardware ethernet 00:02:c3:d0:e5:83;
                        fixed-address 40.175.42.254;
                }
        
                # Laser printer obtains IP address via DHCP. This assures that the
                # printer with this MAC address will get this IP address every time.
        
                host laser-printer-lex1 {
                        hardware ethernet 08:00:2b:4c:a3:82;
                        fixed-address 192.168.1.120;
                }
        }
 #restart the DHCP daemon/service

A. Webserver (HTTPD)
It is assumed that you have the httpd package installed for the particular Linux flavor you chose. Now configure the httpd.conf file as follows

NOTE: Please ensure that the backup file for httpd.conf is kept to avoid messing around the system.


In the next exercise, we will configure the website, example
www.lab1.com on our server.


# vi /etc/httpd/conf/httpd.conf


NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin     webmaster@lab1.com
    DocumentRoot /var/www/html/lab1.com
    ServerName    lab1.com
    ServerAlias    www.lab1.com
    ErrorLog    logs/lab1.com-error_log
    CustomLog     logs/lab1.com-access_log common
    DirectoryIndex  index.html
</VirtualHost>


#/etc/init.d/httpd restart

# Now go to the browser and try to open the site www.lab1.com
If everything goes well, you should be able to open the httpd test page via www.lab1.com
 
P.S. The configuration file had been tested during one of the classes that I took for the government IT officials. Should you come across any issues, please let me know.



Post a Comment

0Comments

Will review your comment and get back!

Post a Comment (0)