Friday, September 21, 2012

Configuring a DHCP server on Ubuntu 11.04

In our LAN we add a static IP address to our machines and access the network. However yesterday we received a newer device to the lab which is preconfigured for DHCP. So, I wanted to connect it to our LAN for testing without changing it's configurations. Actually to change this devices configurations I have to login to it via SSH that means it has to be connected to the network. Therefore the only way I had was to temporarily set up a DHCP server in our lab so that our new device can acquire a IP address from the DHCP server.

I had to search the web to find how to do it since I hadn't done such a thing before. To avoid forgetting what I did, I'm writing it down here. The machine I used to set up the DHCP server is running Ubuntu 11.04. So, here's the steps I followed.

1. Open a terminal and issue the following commands to install the DHCP server.

      sudo apt-get update
      sudo apt-get install dhcp3-server

At the end of the installation it will show an error message saying it couldn't start the DHCP server. This is OK since we haven't still configured the server. After configuring we can start it manually.

2. Now issue the following command to open the configuration file of the DHCP server.

      sudo nano /etc/dhcp/dhcpd.conf

3. It's time to add our configuration details of the DHCP server. Here's the information I have about my requirement. The IP address of the DNS server is 192.248.16.91. Gateway IP address is 10.16.79.254. Our network address is 10.16.68.0. Netmask is 255.255.255.0. Broadcast address is 10.16.79.255. 

I need my DHCP server to assign IP addresses to requesters in the IP address range from 10.16.68.60 to 10.16.68.65. So, remove the current content in the opened file and add the following content. I have included my configurations and therefore anyone else have to put their correct information.

 ddns-update-style none;  
 option domain-name-servers 192.248.16.91;  
 default-lease-time 86400;  
 max-lease-time 604800;  
 authoritative;  
 subnet 10.16.68.0 netmask 255.255.255.0 {  
     range 10.16.68.60 10.16.68.65;  
     option subnet-mask 255.255.255.0;  
     option broadcast-address 10.16.79.255;  
     option routers 10.16.79.254;  
 }  

After adding the content, save and exit from the nano editor.

4. Its time to start the server. You can start it by issuing the following command.

      sudo /etc/init.d/isc-dhcp-server start

5. Now we can check whether the DHCP server works. For that I connected another computer to the LAN and put it on DHCP mode. So, this second computer should acquire a IP address from my DHCP server. By issuing a 'ifconfig' command on this second machine I realised that it has acquired the IP address 10.16.68.62 which is between the rage I mentioned in the DHCP server. So it works.

We can see what is going on from the DHCP server running machine by issuing the following command.

      sudo tail /var/lib/dhcp/dhcpd.leases

It showed the details of the second machine which acquired a IP address from the DHCP server. Additionally following command can be used to see the activities of the DHCP server.

      tail -n 100 /var/log/syslog

So, now our DHCP server works fine. The actual reason for setting up a DHCP server in our lab was we recently received a Raspberry Pi single board computer. The operating system I used to boot it is preconfigured for DHCP. So, that's why I needed a DHCP server to test our Raspberry Pi.




No comments:

Post a Comment