Networking - DHCP

Using DHCP (Dynamic Host Configuration Protocol), you can have an IP address and other information automatically assigned to the hosts connection to your network. This method is quite efficient and convenient for large networks with many hosts, because the process of manually configuring each host is quite time consuming. By using DHCP, you can ensure that every host on your network has a valid IP address, subnet mask, broadcast address and gateway, with minimum effort on your part. A scheme of DHCP for home network is given below.

Figure: In home network, DHCP server has a constant IP and clients are getting dynamic IP from DHCP.

Your Internet service provider, ISP might use a DHCP service to assign your computer an IP address when you connect to the Internet. This is commonly referred to as a dynamic IP address. Each time your computer connects to the Internet, a different but unique number might be assigned to it.

To install DHCP service in a home network we should remember that in which computer DHCP is installed has a constant IP address and DHCP shouldn’t be installed more than once in a network.

The package of DHCP in Linux is dhcp.rpm which comes with Linux installation CD.

[root@www RPMS]# rpm -ivh dhcp-3.0.1rc12-4.i386.rpm

warning: dhcp-3.0.1rc12-4.i386.rpm: V3 DSA signature: NOKEY, key ID 4f2a6fd2

Preparing... ########################################### [100%]

1:dhcp ########################################### [100%]

After installation of the package it creates a configuration file of DHCP named "dhcpd.conf" in /etc directory. Often we can’t find this configuration file in /etc directory after installation. On that case we should share a sample file named dhcpd.conf.sample of DHCP configuration file from /usr/share/doc/dhcp-3.0.1rc12 directory.

[root@localhost root]# cat /usr/share/doc/dhcp-3.0.1rc12/dhcpd.conf.sample > /etc/dhcpd.conf

[root@localhost root]# vi /etc/dhcpd.conf

ddns-update-style interim;

ignore client-updates;

subnet 192.168.0.0 netmask 255.255.255.0 {

# --- default gateway

option routers 192.168.0.1;

option subnet-mask 255.255.255.0;

option nis-domain "domain.org";

option domain-name "domain.org";

option domain-name-servers 192.168.1.1;

option time-offset -18000; # Eastern Standard Time

# option ntp-servers 192.168.1.1;

# option netbios-name-servers 192.168.1.1;

# --- Selects point-to-point node (default is hybrid). Don't change this #unless

# -- you understand Netbios very well

# option netbios-node-type 2;

range dynamic-bootp 192.168.0.128 192.168.0.255;

default-lease-time 21600;

max-lease-time 43200;

# we want the nameserver to appear at a fixed address

host ns {

next-server marvin.redhat.com;

hardware ethernet 12:34:56:78:AB:CD;

fixed-address 207.175.42.254;

}

}

After editing the file, we shall start the DHCP service,

[root@localhost root]# service dhcpd start

ð It starts DHCP server. Now in the network, client can take IP address dynamically from this server.

DHCPD Command: The Internet Software Consortium DHCP Server, dhcpd, implements the Dynamic Host Configuration Protocol (DHCP) and the Internet Bootstrap Protocol (BOOTP). DHCP allows hosts on a TCP/IP network to request and be assigned IP addresses, and also to discover information about the network to which they are attached. BOOTP provides similar functional- ity, with certain restrictions.

[root@localhost root]# dhcpd

ð Now all the clients receive the IP address, subnet mask, gateway and broadcast address from the DHCP server.

[root@localhost root]# dhclient

ð To get IP address dynamically from DHCP, client can use this command.

[root@localhost root]# vi /var/lib/dhcp/dhcpd.leases

/var/lib/dhcp/dhcpd.leases

# All times in this file are in UTC (GMT), not your local timezone. This is

# not a bug, so please don't ask about it. There is no portable way to

# store leases in the local timezone, so please don't request this as a

# feature. If this is inconvenient or confusing to you, we sincerely

# apologize. Seriously, though - don't ask.

# The format of this file is documented in the dhcpd.leases(5) manual page.

# This lease file was written by isc-dhcp-V3.0.1rc12

ð All information of IP addresses (which IP address is given by DHCP server to client’s computer) is stored in this file.