Raspberry Pi as a DHCP and DNS server
Introduction
This blog article talks about migrating my DHCP server away from a wireless router and why you would want to setup a lightweight DHCP server on Linux.
Current Issues with the Existing ASUS RT-N16 Router
I was currently using an ASUS RT-N16 router with Tomato firmware for my wireless (multiple SSIDs), DHCP, DNS, quasi VPN, and internet router. The router was good for its time and is way past its end of life. Even though you can setup OpenVPN on it, the problems is that the NVRAM capacity is too small to handle multiple configurations. Some of these can be VPN certificates, static address assignments etc.
Firmware flashing is one thing but the NVRAM has a limited number of writes and any config or save done, even if it's just a character would mean a write of the entire NVRAM block. As NVRAM is flash memory ,each write to the NVRAM reduces its life.
Point to Note 1) The less changes you can make on your SOHO wireless router the better. As less writes will be made to your NVRAM. and will cause your router to last longer.
Once the NVRAM fails, resetting or firmware updating will not help. Unless you can change your NVRAM chip, best to recycle your router than to keep it as a paperweight. Maybe re-use the power adapter, antenna etc.
With these issues, I eventually migrated most services from this router. The VPN and firewall/internet router features were first migrated, then the wireless was replaced with an Ubiquiti AP and controller. DHCP was the last to migrate. Details of why it's the last will be explained later.
In addition to limited NVRAM capacity, the age or the router begins to show with the time it takes to boot up and start issuing IP addresses. Integrated Services Routers are great but with too many components and to keep costs down the components are cheaper resulting in a shorter life span than enterprise ISRs.
Slow boot up times means slow issuing of IP addresses, means devices cannot get access to the internet when they startup.
This is more for power failures, where once power is restored, all running devices will power on automatically. Even with a UPS, if the battery is drained and shuts down, the same process will happen as if there were no UPS. It is possible to add a delay when devices are powered on (a-la breakermatic devices), but that's for another blog post.
Either way devices boot up and start looking for an IP address. No IP from a DHCP server means
APIPA assigned IP addresses or none at all. Statically assigned devices are great but it's difficult to do this for IoT.
Rule of thumb 1) for static IP addresses. ALWAYS have a reservation for these static IP devices. Preferably with their correct MAC addresses. Why? Should the devices' network configuration be reset, at least the IP address will be the same. Do this for VM's where their MAC addresses can change by the host if live migrations are done between hosts. Once migration is completed and the MAC address is changed, just update it in the reservation and keep a note of the previous MAC address.
Anyhow, back to getting a replacement wireless router, even though it's a good idea to get a replacement wireless router as it's newer, faster etc. the problems is that you will want to use it for more than just a DHCP server. And the more services you use on it, the more critical it becomes to your day to day operations, which means you would not want to restart it for maintenance, or if it fails (hardware or software).
Separating the services is a good idea at home or SOHO once the server hosting the service is low cost, manageable and lightweight.
Low cost is for obvious reasons, can't spent USD $200 on a simple DHCP server. You may want to then beef it up into a bigger server (RAM, storage), and fall into the trap of maximising the resources that you have.
Manageable, in that it doesn't take too much time to setup AND time to maintain it.
Lightweight in that it uses little resources in terms of CPU, Memory and disk space, maybe even low power consumption.
So the options are:
1) Windows DHCP server in a VM.
2) Windows Server in a VM with a third party DHCP server <-- don't know why you want to do this.
3) Windows DHCP server on a Micro PC (your USD $200 item)
4) Linux DHCP server (minimum or no GUI) in a VM.
5) Linux DHCP server (minimum or no GUI) on a MicroPC
6) Linux DHCP server on a single board ARM proc PC (e.g. Raspberry Pi).
Options 1) and 2) are easy to setup but are resource heavy (yeah, you say you can use Server Core or Nano) but management is too much for a home or SOHO. Then there are the licensing costs and the updates.
Option 3) is more that you will want to maximise your MicroPC.
Options 4) and 5) are great. No licensing costs, and the configurations are simple and stable.
Running in a VM there is the risk of the host failing AND the VMs may take too long to boot up. Then there is the chicken and egg scenario with the host waiting for the DHCP VM to boot up to lease IPs.
Rule of Thumb 2) For DHCP, get the fastest boot up device that can host this service.
DHCP is not supposed to be heavy. DNS maybe is but that's an added feature you can choose to use or not on the same device.
You may think a CISCO router can do the job, but tell me how long does it take to boot up?
You say a router should always be on backup power so restarts are minimal? What about your DHCP server? It can also be on backup power.
You say a router uses very little power? How about the RaspBerry Pi? is 10W of power too much?
So you see where this is going.
Option 6) is the best option so far. A low powered device that boots up fast and can run Linux.
Pi it is.
Why a Linux Alternative?
So why a Linux alternative to the router?
If you need to include optional information in your DHCP leases, unless the routers use a proper implementation of a Linux kernel/flavour you may not be able to add more options and additional features.
A lightweight version of Linux will boot fast.
It is highly customisable.
I need it to supply the following options:
dhcp-option=3,192.168.1.1
dhcp-option=5,192.168.1.1
domain=[DOMAIN-NAME]
Should you look at implementing a Linux based DHCP server in your enterprise network and need to add KMS server options in your DHCP leases use the following options in your config file:
srv-host=_vlmcs._tcp.[DOMAIN-NAME],[HOSTNAME1].[DOMAIN-NAME],1688,1
srv-host=_vlmcs._tcp.[DOMAIN-NAME],[HOSTNAME2].[DOMAIN-NAME],1688,2
More info on KMS and DNS can be found at
Univ. Cornell's website, and
Eric Ellis' blog.
Later on I would include next servers in my DHCP leases.
Btw, I tried using
SOPHOS UTM for Home (
https://www.sophos.com/en-us/products/free-tools/sophos-utm-home-edition.aspx) for DHCP but it doesn't have the ability to add these options and/or are not properly documented. Plus, as a UTM, its boot up time will be slow, (based on whatever HW it is running on) so not good for home with power failures and IoT. Actually it's boot up time is faster than my ageing ASUS RT-N16 router.
Which DHCP server service to use?
I prefer
DNSMASQ (not DHCPD) is the best Linux DHCP server.
All the configurations are done via ssh and the modifications of the corresponding config file. DNSMASQ is highly customisable.
Even though DHCPD has a feature for load balancing DHCP servers, it doesn't work too well. At that point I didn't plan to setup or have an active passive failover implementation using DHCPD so I never bothered to continue to use it. DNSMASQ doesn't have load balancing (
it would be a nice feature to implement in the future) but with config files, it can facilitate an active/passive implementation. That will be for another blog.
So a lightweight version of Linux running DNSMASQ on a Raspberry Pi is the best option for me.
Pi Problems
In my initial attempts to use a Raspberry Pi and Raspian was that the MAC address was always changing each time the Pi was restarted/power cycled. Not good if you want to set a reservation based on MAC address and setting a static IP address was also a pain. After days of searching, I found no definitive solution online, forum or even blog post. Plus, I didn't want to spend time researching a solution (and then blogging about it :)
So if I cannot set a static IP address, the Pi is worthless as a DHCP server. Project shelved for over a year.
Until a good friend introduced me to DietPi,
https://www.dietpi.com/
Lighter than
Raspbian and can actually configure a static IP address without hooking it up to a TV or monitor.
For my adventures in the DietPi, check this blog article out, "
Net Admin Adventures in 2019 - DietPi on Raspberry Pi as DHCP and DNS server".
Summary
Ageing wireless routers have a limited lifespan due to their low cost components. The NVRAM is the most affected with its limited writes.
In selecting a replacement device, a Raspberry Pi can adequately function as a DHCP server once you can get Linux distribution to run on it allowing easy configuration of static IP address.
Step 1) Identify services to migrate.
Step 2) Identify your various hardware options, cost, configurability, maintenance and resource overhead.
Step 3) For each service, look at the various options that can be used. If it can be done on a low-powered device than a VM it may be the better option.
Step 4) Select your hardware/software solution and implement.
Point to Note 1) The less changes you can make on your SOHO wireless router the better. As less writes will be made to your NVRAM. and will cause your router to last longer.
Rule of thumb 1) for static IP addresses. ALWAYS have a reservation for these static IP devices. Preferably with their correct MAC addresses.
Rule of Thumb 2) For DHCP, get the fastest boot up device that can host this service.
Read my blog "
Net Admin Adventures in 2019 - DietPi on Raspberry Pi as DHCP and DNS server" for the next steps on the Raspberry Pi.
Naresh
2019/06/08