Adding a DHCP server
Next step in this master plan is to add a DHCP server to the PI that is running my DNS server and NTP server. Doing this step means that the DNS server on my PI will become the goto DNS server for my entire network. At the moment, the default is 192.168.1.1 (my router) for my lan computers and 192.168.1.6 (by DHCP/DNS/NTP server) for my VPN. This is inconsistent and means that I cannot use my DNS names for computers on my LAN – which could be confusing. By switching my DHCP over to my PI, I can get full control of the DNS part and have that routed first to my PI, then on to the internet.
Before I break anything, first things first. Backup my PI! Only need to do the DNS Server this time as all the configuration will be done on that and on my Router (Turning off DHCP once everything is working properly)
For this project I’m going to be using this post as a reference guide.
apt–get -y install isc–dhcp–server
There is a section in the post about editing resolv.conf this lets you add more name servers to try when looking things up.
nano /etc/resolv.conf
My resolve file looks like this
# Generated by resolvconf
nameserver 127.0.0.1
I’m adding these two entries to the file.
domain lan.cjdawson.com
search lan.cjdawson.com
This should ensure that the host list is set properly. Not sure if it is really needed though.
I’m going to see if I can do this upgrade without modifying this file. If I have too modify it I’ll add something like this…
Find this section, it should be at the bottom of the file.
Change the INTERFACES=”” to the interface you want the DHCP service to send requests, the Raspberry Pi only has one interface so this is Eth0.
INTERFACES=”etho”
Now we need to edit the actual DHCP configuration file. Edit the following:
nano /etc/dhcp/dhcpd.conf
Most of the file is commented out and contains helpful examples, find the following:
# option definitions common to all supported networks…
option domain-name “example.org”;
option domain-name-servers ns1.example.org, ns2.example.org;
and change it too
option domain-name “lan.cjdawson.com”;
option domain-name-servers 127.0.0.1;
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.
subnet 192.168.1.0 netmask 255.255.255.0 { option routers 192.168.1.1; option subnet-mask 255.255.255.0; option broadcast-address 192.168.1.255; option domain-name-servers 194.168.1.6; option ntp-servers 192.168.1.6; # option netbios-name-servers 192.168.1.1; # option netbios-node-type 2; range 192.168.1.100 192.168.1.200; default-lease-time 600; max-lease-time 7200; }
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:
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).
Let’s enable the DHCP server with
systemctl enable isc-dhcp-server
and let’s start it with
systemctl start isc-dhcp-server
I’ve come across a problem that my Bind9 and isc-dhcp-server servers struggle to start when I boot my PI. This is going to be a problem for the device that is supposed to be looking after my network. For now, I’ve fixed it as follows.
raspi-config
Choose option 4 – Wait for Network as Boot
Then choose
Slow Wait for network connection before completing boot
Doing this seems to fix the problem, however, it would like to come up with a solution that will work with a fast boot – this will be a job for later.