Raspberry Pi – Installing DHCP Server

isc-dhcp-server version 4.2.2.dfsg.1-5
Raspbian 2013-02-09-wheezy-raspbian

Getting a dhcp server up and running on the Raspberry Pi is easy to do. Once you have the latest version of Raspian installed and have the updates for apt-get install you are ready to do. You start the process by installing the dhcp server.

sudo apt-get install isc-dhcp-server

You will need to assign a static address to the ethernet interface to start the process. Edit the /etc/network/interfaces file using nano substituting the address below with what you will be using on your network –

iface eth0 inet static
address 192.168.12.2
netmask 255.255.255.0
gateway 192.168.12.254

[youtube]http://youtu.be/FRUuIArpuwQ[/youtube]
The next step will be installing the dhcp server – sudo apt-get install isc-dhcp-server

When isc-dhcp-server tries to automatically startup, it will fail. We need to activate the static ip address that we setup earlier. To be on the safe side, do a sudo ifdown eth0. If you get a failure message, like you see in the YouTube video, that is normal. Next will be to startup the interface using sudo ifup eth0. If all does well, you should see any messages. Using ifconfig should show the static address that you configured.

Now we need to configure the dhcp server by using the following command –
sudo nano /etc/dhcp/dhcpd.conf

These first two commands are “global” and will be used for all of the subnet declarations you will setup for your dhcp server. Putting a # in front of any line comments it out and therefore inactive on the DHCP configuration.

option domain-name “mydomain.org”;
option domain-name-servers 8.8.8.8, 8.8.4.4;

These next few lines will be where you setup the ip pool for the subnet you are going to use it for. Using a # will serve as a comment line and help you identify each of the address pools you may be using. Each of the lines will need to end with a semicolon. Any lines that you miss will be flagged with an error to help you find it.

# Put a comment here about the purpose of the dhcp server
subnet 192.168.12.0 netmask 255.255.255.0 {
range 192.168.12.2 192.168.12.20;
option routers 192.168.12.1;
}

Once you save the the config, you will need to restart the dhcp service
sudo service isc-dhcp-server restart.

You can see what is going on by doing a tail of /var/log/syslog or /var/log/messages.

This message from /var/log/messages indicates that your dhcp server is seeing traffic from a workstation. There should be a corresponding line with the same message with DHCPACK instead of DHCPREQUEST.

Indicates assignment of address from dhcp server
tail /var/log/messages
Mar 24 23:35:29 raspberrypi dhcpd: DHCPREQUEST for 192.168.12.3 from 58:b0:35:fe:87:d1 via eth0

When you need help on configuration the ISC-DHCP-Server, you will use man dhcpd.

To see more of my posts about the Raspberry Pi, please go to http://www.ronnutter.com/category/raspberry-pi/

Send to Kindle
This entry was posted in Blog Entries, Raspberry Pi, Video Podcast and tagged . Bookmark the permalink.