DHCP (Dynamic Host Configuration Protocol) is a protocol that handles the assignment of IP addressess to clients that don’t a static IP address automatically. It includes the IP parameters such as subnet masks, default gateway and IP addressess of DNS server.
When computers connect to a network it will search DHCP server for reserved IP address. If the IPs are available then DCHP server will assign them an IP address, Gateway, DNS etc.
Dynamic addressing will reduce the job of network administrator because the software keeps track of IP addressess rather than requiring an administrator to manage the task. With DHCP server a new computer can be connected to a network without do manually setup a unique IP address.
Step 1. Installing DHCP Server
taufanlubis@zyrex:~$ sudo apt-get install dhcp3-server
Password:
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following NEW packages will be installed:
dhcp3-server
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 302kB of archives.
After unpacking 856kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com feisty/main dhcp3-server 3.0.4-12ubuntu4 [302kB]
Fetched 302kB in 5s (56.3kB/s)
Preconfiguring packages …
Selecting previously deselected package dhcp3-server.
(Reading database … 154991 files and directories currently installed.)
Unpacking dhcp3-server (from …/dhcp3-server_3.0.4-12ubuntu4_i386.deb) …
Setting up dhcp3-server (3.0.4-12ubuntu4) …
Generating /etc/default/dhcp3-server…
* Starting DHCP server dhcpd3 [fail]
invoke-rc.d: initscript dhcp3-server, action “start” failed.
taufanlubis@zyrex:~$
Step 2. Configuring The DHCP server
After the installation finished, we have to configure the DHCP server before it can run. We have to tell the DHCP server:
-
the range of IP addressess that can be used by clients
-
which gateway can be accessed
-
DNS addressess
-
etc
In this practice, let’s try with a case.
Our Network IP range is: 192.168.0.1 – 192.168.0.254 (254 IP addressess)
(192.168.0.0 if for network address and 192.168.0.255 is for broadcasting address, so we can’t use it)
Sub netmask: 255.255.255.0
Gateway to internet: 192.168.0.1
DNS from ISP: 202.134.2.5 and 202.134.0.155 (telkom speedy)
Our DHCP IP address is: 192.168.0.2
Range of IP addressess that we want to set is: 192.168.0.100 – 192.168.0.200 (100 IP addressess)
The configuration filre of our DHCP server is /etc/dhcp3/dhcpd.conf.
taufanlubis@zyrex:~$ cd /etc/dhcp3
taufanlubis@zyrex:/etc/dhcp3$ ls -l
total 16
-rw-r–r– 1 root root 1558 2007-04-02 16:46 dhclient.conf
drwxr-xr-x 2 root root 4096 2007-07-31 08:38 dhclient-enter-hooks.d
drwxr-xr-x 2 root root 4096 2007-04-15 18:56 dhclient-exit-hooks.d
-rw-r–r– 1 root root 3551 2007-04-02 16:46 dhcpd.conf
taufanlubis@zyrex:/etc/dhcp3$
Before we change the configuration, always make a back up. In case we may make a mistake.
taufanlubis@zyrex:/etc/dhcp3$ sudo cp dhcpd.conf dhcpd.conf.original
Password:
taufanlubis@zyrex:/etc/dhcp3$
taufanlubis@zyrex:/etc/dhcp3$ sudo gedit dhcpd.conf
#
# Sample configuration file for ISC dhcpd for Debian
#
# $Id: dhcpd.conf,v 1.1.1.1 2002/05/21 00:07:44 peloy Exp $
#
# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages (‘none’, since DHCP v2 didn’t
# have support for DDNS.)
ddns-update-style none;
# option definitions common to all supported networks…
option domain-name “example.org”;
option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600;
max-lease-time 7200;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;
# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
#subnet 10.152.187.0 netmask 255.255.255.0 {
#}
# This is a very basic subnet declaration.
#subnet 10.254.239.0 netmask 255.255.255.224 {
# range 10.254.239.10 10.254.239.20;
# option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
#}
Now, change the configuration to be like below (remove everything):
ddns-update-style none;
option domain-name-servers 202.134.2.5, 202.134.0.155;
default-lease-time 86400;
max-lease-time 604800;
authoritative;
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.100 192.168.0.200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.0.255;
option routers 192.168.0.1;
}
Save it. It is very simple and basic configuration only but it’s enough to run our DHCP server. I’ll explain about the configuration after.
Step 3. Restart the DHCP server
Now, let’s a try first.
Restart the DHCP server.
taufanlubis@zyrex:~$ sudo /etc/init.d/dhcp3-server restart
* Stopping DHCP server dhcpd3 [fail]
* Starting DHCP server dhcpd3 [ OK ]
taufanlubis@zyrex:~$
When you see ‘fail’ at ‘ Stopping DHCP server dhcpd3′, it’s ok. Because, it’s never run before, right? So, just ignore it.
If you restart the DCHP server again then the ‘fail’ message is gone.
taufanlubis@zyrex:~$ sudo /etc/init.d/dhcp3-server restart
* Stopping DHCP server dhcpd3 [ OK ]
* Starting DHCP server dhcpd3 [ OK ]
taufanlubis@zyrex:~$
Note:
DHCP Server Service will not run if your IP address Computeris set to ‘Automatic Configuration (DHCP). So, make sure that the machine have an IP address before you start DHCP server service.
To test it, I have a PC using OpenSuse10 that connect to my Ubuntu Feisty DCHP server.
Let’s see if we are success or not.
The network configuration below was taken from my OpenSuse10 PC.
Client IP : 192.168.0.199
Netmask : 255.255.255.0
taufanlubis@linuxserver:~> su root
Password:
linuxserver:/home/taufanlubis # ifconfig
eth0 Link encap:Ethernet HWaddr 00:0D:88:B3:72:F3
inet addr:192.168.0.199 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::20d:88ff:feb3:72f3/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:5 errors:0 dropped:0 overruns:0 frame:0
TX packets:86 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:864 (864.0 b) TX bytes:9688 (9.4 Kb)
Interrupt:177 Base address:0xb800
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:86 errors:0 dropped:0 overruns:0 frame:0
TX packets:86 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:6152 (6.0 Kb) TX bytes:6152 (6.0 Kb)
linuxserver:/home/taufanlubis #
linuxserver:/home/taufanlubis # route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
linuxserver:/home/taufanlubis #
linuxserver:/home/taufanlubis # cat /etc/resolv.conf
# generated by NetworkManager, do not edit!
nameserver 202.134.2.5
nameserver 202.134.0.155
linuxserver:/home/taufanlubis #
Check if DHCP Server service has been running
taufanlubis@zyrex:~$ grep bootps /etc/services
bootps 67/tcp # BOOTP server
bootps 67/udp
taufanlubis@zyrex:~$
You can check also using:
taufanlubis@zyrex:~$ netstat -uap
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
udp 0 0 *:32770 *:* -
udp 0 0 *:913 *:* -
udp 0 0 *:bootps *:* -
udp 0 0 *:bootpc *:* -
udp 0 0 *:sunrpc *:* -
taufanlubis@zyrex:~$
DHCP is running on the bootps UDP port which translates to port 67 UDP.
You can it using:
taufanlubis@zyrex:~$ grep bootps /etc/services
bootps 67/tcp # BOOTP server
bootps 67/udp
bootps means port 67.
The DHCP server writes all current IP addressess “leases” to the file /var/lib/dhcp3/dhcpd.leases.
taufanlubis@zyrex:~$ cat /var/lib/dhcp3/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.4
lease 192.168.0.199 {
starts 5 2007/10/05 22:37:02;
ends 5 2007/10/05 23:37:02;
tstp 5 2007/10/05 23:37:02;
binding state free;
hardware ethernet 00:0d:88:b3:72:f3;
}
lease 192.168.0.200 {
starts 5 2007/10/05 21:56:50;
ends 6 2007/10/06 21:56:50;
tstp 6 2007/10/06 21:56:50;
binding state active;
next binding state free;
hardware ethernet 00:90:f5:36:9a:eb;
client-hostname “zyrex”;
}
taufanlubis@zyrex:~$
Another Configuration
DHCP server can set fixed ip addressess to group of clients as long as you have their MAC addressess.
For example, the ‘test computer’ has MAC ‘hardware ethernet 00:0d:88:b3:72:f3;’.
Just add the configuration scripts below into your DCHP file configuration.
host our_test_pc {
hardware ethernet 00:0d:88:b3:72:f3;
fixed-address 192.168.0.23
}
so it will become like this:
ddns-update-style none;
option domain-name-servers 202.134.2.5, 202.134.0.155;
default-lease-time 86400;
max-lease-time 604800;
authoritative;
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.100 192.168.0.200;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.0.255;
option routers 192.168.0.1;
}
host our_test_pc {
hardware ethernet 00:0d:88:b3:72:f3;
fixed-address 192.168.0.23
}
That configuration says:
Set dynamic ip addressess from 192.168.0.100 to 192.168.0.200
Set fixed ip address for our_test_pc : 192.168.0.23
Save the file and restart the DHCP server.
taufanlubis@zyrex:~$ sudo /etc/init.d/dhcp3-server restart
* Stopping DHCP server dhcpd3 [ OK ]
* Starting DHCP server dhcpd3 [ OK ]
taufanlubis@zyrex:~$
Now, let’s check our test computer.
linuxserver:~ # ifconfig
eth0 Link encap:Ethernet HWaddr 00:0D:88:B3:72:F3
inet addr:192.168.0.23 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::20d:88ff:feb3:72f3/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:57 errors:0 dropped:0 overruns:0 frame:0
TX packets:263 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6804 (6.6 Kb) TX bytes:28460 (27.7 Kb)
Interrupt:193 Base address:0xb800
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:173 errors:0 dropped:0 overruns:0 frame:0
TX packets:173 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:13535 (13.2 Kb) TX bytes:13535 (13.2 Kb)
linuxserver:~ #
Well, seem that all work. Now, you can see that you can create dynamic and static ip addressess for your clients with DCHP Server Service.
Before I finish this article, I will explain a bit about our dhcp configuration.
ddns-update-style none;
You can tell DHCP to update a DNS server if the IP addressess of a server in your LAN has changed.
We don’t want to update DNS records so just set it to none.
option domain-name-servers 202.134.2.5, 202.134.0.155;
Tell DHCP server which DNS servers it should assign to a client. You can specify more than one DNS server, don’t forget to separate by commas.
default-lease-time 86400;
Tell DHCP server how long clients would like to get an ip addressess. It’s in seconds. So, 86400 mean 24 hours.
max-lease-time 604800;
Tell DHCP server that maximum lease time is 7 days.
authoritative;
subnet 192.168.0.0 netmask 255.255.255.0 {
subnet: subnet to use
netmask: netmask to use
range 192.168.0.100 192.168.0.200;
Ip range is 192.168.0.100 to 192.168.0.200. So, there are 101 ip addressess.
option subnet-mask 255.255.255.0;
subnet-mask: subnet-mask to use
option broadcast-address 192.168.0.255;
broadcast address: 192.168.0.255
option routers 192.168.0.1;
Tell DHCP server the gateway address it should assign to requesting clients.
Default gateway is 192.168.0.1 (gateway will be based on your network setup).
}
Hopefully, my explanation is easty for you to understand.




