DHCP Server with multiple subnet


In my previous post i have explained how to install and configure DHCP server on CentOS. Here we are going to configure the dhcp server with different/multiple subnet network.

Before making the changes in dhcp.conf file, take the backup for safer side.

[root@server.local ~]#cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf_bak20140708

The DHCP daemon listens on all network interfaces unless otherwise specified. The following /etc/sysconfig/dhcpd example specifies that the DHCP daemon listens on the eth0 and eth1 interfaces:

DHCPDARGS="eth0 eth1";

If a system has three network interfaces cards — eth0, eth1, and eth2 — and it is only desired that the DHCP daemon listens on eth0, then only specify eth0 in /etc/sysconfig/dhcpd:

DHCPDARGS="eth0";

For example, we have two network interfaces, eth0 listens to 192.168.1.0/24 network and eth1 listens to 192.168.2.0/24 network. Then the dhcp server configuraiton should be as below settings.

option domain-name "example.com";
option domain-name-servers 192.168.1.100, 192.168.1.200
default-lease-time 600;
max-lease-time 7200;

subnet 192.168.1.0 netmask 255.255.255.0 {
option subnet-mask 255.255.255.0;
option routers 192.168.1.1;
range 192.168.1.1 192.168.1.254;
}

subnet 192.168.2.0 netmask 255.255.255.0 {
option subnet-mask 255.255.255.0;
option routers 192.168.2.1;
range 192.168.2.1 192.168.2.254;
}

Setup DHCP server on CentOS


Dynamic Host Configuration Protocol (DHCP) is used to assign IP addresses, gateway and DNS details automatically to the clients.

we need to configure DHCP server to offering ipaddress details to the clients when it is required.

DHCP Server:

server.local, IP address: 192.168.1.5

DHCP Client:

client.local, IP address: 192.168.1.6

Step 1: DHCP Installation

Run the below command to install dhcp server and client.

[root@server.local ~]#yum install dhcp

Step 2: Assign static ip address to dhcp server

[root@server.local ~]#vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE="eth0"

HWADDR="00:10:5A:44:12:C5"

NM_CONTROLLED="yes"

ONBOOT="yes"

BOOTPROTO="none"

IPADDR=192.168.1.5

NETMASK=255.255.255.0

GATEWAY=192.168.1.1

Step 3: Interface configuration

If you have more than one network interface card in your server then we need to specify on which interface our server will be listen for dhcp request.

By default eth0 interface is listen to dhcp.

[root@server.local ~]#vi /etc/sysconfig/dhcpd

Add the below line;

DHCPDARGS=eth0

Step 4: DHCP Configuration

[root@server.local ~]#cp /usr/share/doc/dhcp-*/dhcpd.conf.sample /etc/dhcp/dhcpd.conf

[root@server.local ~]#vi /etc/dhcp/dhcpd.conf

Make the changes according to your environment setup. Below is the sample configuration for my linux setup.

#specify domain name

option domain-name "example.com";

#specify DNS server ip and additional DNS server ip

option domain-name-servers 192.168.1.100, 192.168.1.200;

#specify default lease time

default-lease-time 600;

#specify Max lease time

max-lease-time 7200;

#specify log method

log-facility local7;

#Configuring subnet and iprange

subnet 192.168.1.0 netmask 255.255.255.0 {

range 192.168.1.1 192.168.1.254;

option broadcast-address 192.168.1.255;

#Default gateway ip

option routers 192.168.1.1;

}

#Fixed ip address based on MAC id

host laserjet
{
hardware ethernet 00:10:5A:44:15:Z5;
fixed-address 192.168.1.50;
}

Step 5: Start the DHCP service

[root@server.local ~]#/etc/init.d/dhcpd start

[root@server.local ~]#chkconfig dhcpd on

Step 6: Configuring a DHCP Client

Log in to client machine (client.local/192.168.1.6) and perform the below steps on linux terminal.

[root@client.local ~]#vi /etc/sysconfig/network

NETWORKING=yes

[root@client.local ~]#vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

BOOTPROTO=dhcp

ONBOOT=yes

Restart the network services

[root@client.local ~]#/etc/init.d/network restart

Check your ip address and network details.

[root@client.local ~]#ifconfig -a

[root@client.local ~]#cat /etc/resolv.conf

Below command is used to view your current DHCP leases machines.( from DHCP Server)

[root@server.local ~]#cat /var/lib/dhcpd/dhcpd.leases

That’s it!