/DHCP

DHCP

DHCP stands for “Dynamic host configuration Protocolwhich , as you probably know used for dynamic configuration of a host on a network . That is , no local configuration is needed form the client, so let’s just cut this and move to how it works , the server and the client exchange the following packets :

1- DHCPDISCOVER : once the client boots up, it sends a broadcast to the DHCP server requesting an address

2- DHCPOFFER : the DHCP server(s) will then reply with an “offer” including the ip-address , other configurations and the maximum lease* time , the client will the receive the offer(s) , and will select one of them (usually the one with longest lease time)

3- DHCPREQUES : the client will the send a request to the server to confirm the    selected offer.

4- DHCPACK : the server acknowledges the request after saving the client’s configuration and you’re good to go.

I mentioned abovelease time” , it’s the time the client is allowed to use the configurations assigned to it , once it’s over , two scenarios may happen:

1-The client abandons the lease ( sends DHCPRELEASE): that tells the server it no longer needs the assigned address.

2-Renew the lease : the client will send a DHCPREQUEST to the server , if the server replies with DHCPACK the time lease will then be renewed , however the server may not reply and the client will have to go through  the whole assignment process all over again after DHCPRELEASE of course.

– – – – – – – – – – –

Now for the configuration part :

first have the DHCP service installed :

Redhat: yum install dhcp or Ubuntu/Debian : apt-get install dhcp3-server

but don’t start the server now , you need it configured first , configuration files are in /etc/dhcpd.conf (redhat) or in /etc/default/dhcp3-server (Ubuntu/Debian)

Alright that’s a minimal configuration for the server , the first line is for dynamic DNS , to make host to name and vice versa lookups dynamic .. that’s a whole other story never mind it for now but add it anyway.

Now for the main part which is pretty staright forward

I declare the subnetwork 192.168.1.0 whose netmask is 255.255.255.0 and set its settings between the braces :

1- assign addresses only form range 192.168.1.4 to 192.168.1.254 this is important as you don’t want any conflicts on your network , I guess the names of the rest really do explain their selves.

2 assign the values of the leases :

Default lease : A client may request a specific length of time that a lease will be valid. Otherwise the server will assign a lease with this expiry value (in seconds).

Maximum lease : This is the maximum length of time that the server will lease for. If a client requests a longer lease, a lease will be issued, although it will only be valid for the max-lease-time .

now save the file , and test the syntax :

#-/etc/rc.d/init.d/dhcpd configtest (this will differ in other distros)

if you get "Syntax:OK" then you're good to go let's start the server :

#-service dhcpd start

Now let’s see the client’s request : $-dhclient

As you can see it got a random address , did you notice the packets ?

Here’s what happens when I renew : **

3-let’s say I want some host to get a static address no matter what , this will be based on its MAC ,That’s why I declared some host with a random name “x” in the braces I state it’s MAC and the address I want to use , restart the server and try


Perfect ! You can try $-ifconfig to check the rest of the configurations.

Finally,you should know that When a dhcpd server is running it will generate entries in the file: /var/lib/dhcp/dhcpd.leases which is very important , the server wont start if the file is missing.

this is a minimal configuration for more options “alot of options” make sure you check #-man dhcp-options which also will guide you through the syntax for the dhcpd.conf file.

I’ll end with a little question .. based on the output of the renewal (the photo marked **) is it the same machine as the first one ?