Friday, August 29, 2014

CentOS : Setup DHCP Server

DHCP Server is used to distribute IP addresses to the clients in your network. DHCP stands for Dynamic HostConfiguration Protocol. It reduces the work burden to a system admin if he/she have to assign IP addresses manually to more than 100+ systems.

Installation

To install DHCP server on CentOS 6.5, enter the following command:
yum install dhcp -y

Configuration

DHCP server configuration is not that difficult. First, we have to assign which interface you want your DHCP server to run on. In my case, I have only one Interface on my system (eth0), so I assigned eth0.
To do that, edit file /etc/sysconfig/dhcpd,
vi /etc/sysconfig/dhcpd
Assign the network interface:
# Command line options here
DHCPDARGS=eth0
Save and close the file. Then, copy the sample dhcp configuration file to /etc/dhcp/ directory.
cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
Now, edit dhcpd.conf file,
vi /etc/dhcp/dhcpd.conf
Make the changes as shown below.
Set the domain name and domain-name servers:
[...]

# option definitions common to all supported networks...
 option domain-name "unixmen.local";
 option domain-name-servers server.unixmen.local;

[...]
If this DHCP server is the official DHCP server for the local network, you should uncomment the following line:
[...]
authoritative;
[...]
Define the sunbet, range of ip addresses, domain and domain name servers like below:
[...]
# A slightly different configuration for an internal subnet.
 subnet 192.168.1.0 netmask 255.255.255.0 {
 range 192.168.1.20 192.168.1.30;
 option domain-name-servers server.unixmen.local;
 option domain-name "unixmen.local";
 option routers 192.168.1.1;
 option broadcast-address 192.168.1.255;
 default-lease-time 600;
 max-lease-time 7200;
 }
[...]
If you want to assign a fixed IP address to your client, you should enter it’s MAC id and the IP address in the following directive. For example, I want to assign a fixed IP address 192.168.1.15 to my Ubuntu client, hence I modified the following directive as shown below.
[...]
host ubuntu-client {
 hardware ethernet 00:22:64:4f:e9:3a;
 fixed-address 192.168.1.15;
 }
[...]
After making all the changes you want, save and close the file. Be mindful that if you have another unused entries on the dhcpd.conf file, comment them. Otherwise, you’ll have issues while starting dhcpd service.
Now, start the dhcpd service and make it to start automatically on every reboot.
service dhcpd start
chkconfig dhcpd on

Configure Clients

Now, go to the client configuration network settings and change the IP settings to Automatic (DHCP).
Here is my Lubuntu 14.04 settings:
Editing Wired connection 1_001
Restart the network or reboot the client system to get IP address automatically from the DHCp server.
Now, you should see the IP address has been automatically assigned to the clients from the DHCP server.
Run the following command from the client system Terminal:
sudo ifconfig
Sample output:
sk@sk: ~_002
As you see in the above picture, My ubuntu client system which has MAC id 00:22:64:4f:e9:3a gets a fixed IP address 192.168.1.15 from the DHCP server.
That’s it. DHCP server is up and ready.
Cheers!

No comments: