Thứ Ba, 7 tháng 10, 2014

Configuring DHCP Server on CentOS/RHEL 6

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.
dhcp

Step 1: Install DHCP Package

First install dhcp packages using package manager yum on CentOS, Redhat system.
# yum install dhcp

Step 2: Edit /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

Step 3: Configuring DHCP

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;
}

Step 4: Restart DHCP

After making all above changes, lets start dhcp service using following command.
# service dhcp start
Similarly to stop and restart dhcp service use following commands.
# 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.
# service network restart

Không có nhận xét nào:

Đăng nhận xét