Setup Raspberry pi as a dhcp server

This post is going to show you the basic steps of creating a DHCP server using a Raspberry pi running the latest version of Raspbian, configure the Raspberry (Linux) to use a fixed IP Address and configure clients to get a static IP address using their MAC address. The software used is isc-dhcp-server available from the Ubuntu software repository. I was fed-up of my router giving random IP addresses to servers when it was meant to hand out the same address.

Install Software

The first step is to install the server software.

Set Static IP Address

The second step is to set a static IP address on the Raspberry pi as this wont be able to start the DHCP service without it. I don’t need to configure NetworkManager as I am not running the Raspberry pi with any GUI. Edit the following file.

The bottom section of the file has been commented out as this is not relevant to the ethernet port I am using.

To get the DNS working we need to edit the resolv.conf file.

Add the above nameservers into the file. You will need to modify to your network. You can use Googles DNS servers instead if you prefer.

Configure the DHCP Server

Now we need to tell the DHCP service the interface to hand out addresses on. Edit the following file:

Find this section, it should be at the bottom of the file.

Change the INTERFACES=”eth0″ to the interface you want the DHCP service to send requests, the Raspberry Pi only has one interface so this is Eth0.

Now we need to edit the actual DHCP configuration file. Edit the following:

Most of the file is commented out and contains helpful examples, find the following:

This Raspberry pi will be acting as the DHCP server in my home LAN. I therefore needed to un-comment the authoritative line.

This section will configure the addresses handed out, the gateway to give to the clients and the DNS servers to give to clients etc.

I have two ranges in my configuration. This is because I don’t want the DHCP server handing out some of these addresses as they will be fixed to certain clients later in the configuration. You can define as many ranges as needed.

Configure Fixed IP’s for clients

Further down the configuration file should be a section for adding fixed IP Addresses. Find something similar to this example:

You can either un-comment this and edit it or create as many as you like after it. For example.

If any of the machines listed above with those MAC addresses then they will get the given fixed IP Address. These are addresses are excluded from the range of addresses handed out by the DHCP server (See above configuration).

Start the DHCP service upon boot

Run this command to make the service start on boot otherwise when the machine is rebooted then any clients in the local network won’t be given an address.

Now you can either start the service by running the following command or reboot the server.

Checking the currently leased addresses

Run this command to check the currently assigned addresses. Please note this does not include the clients given a fixed address. You should see something like this:

Run this command to check the currently leased addresses to the fixed clients. You should see something like this:

References

Ubuntu Forums
How to set a Static IP in Ubuntu – The Proper Way! | Sudo Juice
Setup DHCP Server On Ubuntu 14.04 LTS Server | Unix Men

Please share 🙂
  • Sam

    Very interesting, might have a play with this myself sometime.

  • Pingback: Adding a DHCP server | Colin Dawson()

  • Xavier

    very useful ! I installed pi-hole in about 10 minutes and then 10 more minutes to turn the DHCP on, I cannot believe how ridiculously insane my old Rpi1 has become.
    Thanks !

    • No problem. They are very useful devices, weatherStation, PiHole etc 🙂

  • JihyunNam

    Great job

  • Gururaj Pandurangi

    Hello, is isc-dhcp-server the only package I need to install? I asked because there are no statements shown in any of the commands you have mentioned (especially which you mention “In file already”)