Install and configure DHCP server on CentOS 7 / Ubuntu 14.04

ADVERTISEMENT

Install and configure DHCP server on CentOS 7
Install and configure DHCP server on CentOS 7

Photo by cuteimage, FreeDigitalPhotos.net

Dynamic Host Configuration Protocol is a network protocol used to dynamically distribute network configuration parameters, such as IP addresses, gateway and DNS for network interfaces. DHCP Server assigns IP addresses automatically to all systems, so system admin need not to assign IP addresses manually to client machines in the network. DHCP is the best option for bigger environments, holds thousands of systems.

ADVERTISEMENT
Article will continue after the ad

Environment:

Make sure to have only one DHCP server in your environment, also if you have a router / switch which provides functionality of DHCP, you need to disable it.

  1. CentOS 7 64bit Minimal server (DHCP Server) OR Ubuntu 14.04 64bit Minimal server (DHCP Server)
  2. CentOS 7 64bit Minimal server (DHCP Client) OR Ubuntu 15.04 Desktop (DHCP Client)

Note:  You must a assign a static IP address to your DHCP server.

1. Install and configure DHCP server on CentOS 7:

First let us see how to install and configure DHCP server on CentOS 7 64bit. The should also work on CentOS 6.x and other older versions.

Install dhcp server and client using the below command.

# yum install dhcp

Once tha packages are installed, copy the sample configuration file to /etc/dhcp directory.

# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf

Now, edit dhcpd.conf file,

# vi /etc/dhcp/dhcpd.conf

Do the changes as shown below.

Define the sunbet, range of ip addresses, domain and domain name servers like below:

[...]
# Configuring subnet and iprange
 subnet 192.168.12.0 netmask 255.255.255.0 {
 range 192.168.12.100 192.168.12.200;
# Specify DNS server ip and additional DNS server ip 
 option domain-name-servers 8.8.8.8, 8.8.4.4;
# Specify Domain Name
 option domain-name "itzgeek.local";
# Default Gateway
 option routers 192.168.12.2;
 option broadcast-address 192.168.12.255;
# Specify Default and Max lease time
 default-lease-time 600;
 max-lease-time 7200;
 }
[...]

If you want to assign a fixed IP address to your client, you have to enter it’s MAC id and the IP address in the following stanza. For example, to assign a fixed IP address 192.168.12.110 to client, stanza will look like below.

[...]
host mywindows-client {
 hardware ethernet 00:0C:29:05:A7:CB; 
 fixed-address 192.168.12.110; 
} 
[...]

Now, start the dhcpd service and make it to start automatically on system reboot.

# systemctl restart dhcpd
# systemctl enable dhcpd

That’s it. Now, skip to ‘Configure DHCP Clients’ section and configure your clients to get IP addresses automatically from the DHCP server.

2. Install and configure DHCP server on Ubuntu 14.04:

First let us see how to install and configure DHCP server on Ubuntu 14.04. The should also work on Ubuntu 15.04 / 14.10 / 13.04 / 13.10 and other older versions.

Install dhcp server and client using the below command.

$ sudo apt-get install isc-dhcp-server

Once tha packages are installed, we have to assign on what interfaces should the DHCP server (dhcpd) serve DHCP requests. In our case, have only one Interface on my system (eth0), so we will assign eth0.

Edit file /etc/default/isc-dhcp-server.

$ sudo nano /etc/default/isc-dhcp-server

Mention eth0 in the file.

# Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACES="eth0"

Now, edit dhcpd.conf file,

$ sudo nano /etc/dhcp/dhcpd.conf

Do the changes as shown below.

Define the sunbet, range of ip addresses, domain and domain name servers like below:

[...]
# Configuring subnet and iprange
 subnet 192.168.12.0 netmask 255.255.255.0 {
 range 192.168.12.100 192.168.12.200;
# Specify DNS server ip and additional DNS server ip 
 option domain-name-servers 8.8.8.8, 8.8.4.4;
# Specify Domain Name
 option domain-name "itzgeek.local";
# Default Gateway
 option routers 192.168.12.2;
 option broadcast-address 192.168.12.255;
# Specify Default and Max lease time
 default-lease-time 600;
 max-lease-time 7200;
 }
[...]

If you want to assign a fixed IP address to your client, you have to enter it’s MAC id and the IP address in the following stanza. For example, to assign a fixed IP address 192.168.12.110 to client, stanza will look like below.

[...]
host mywindows-client {
 hardware ethernet 00:0C:29:05:A7:CB; 
 fixed-address 192.168.12.110; 
} 
[...]

Now, start the dhcpd service and make it to start automatically on system reboot.

# sudo service isc-dhcp-server restart

3. Configure DHCP Clients:

Now, you need to configure client machines to get IP address automatically from DHCP server. You can go through below articles.

That’s All.

ADVERTISEMENT

POSTS YOU MAY LIKE -:)

Share This Post

Shares