I made a new NAS box, with an extra USB3.1 2.5GBE adapter. The box is directly connected to my workstation using this interface. However, manually setting up IP and routes feels just bad, so I decided to put up a DHCP server on that specific interface.
Note that link-local addresses are out of question, because using it requires configuration on both sides. Good ol' DHCP works with virtually any system.
There are two popular DHCP servers: isc-dhcp-server
and dnsmasq
. Apparently,
dnsmasq
s simpler to operate:
The ISC tools (dhcpd and bind) have been around a long time (I started using them almost 20 years ago). They're also incredbly powerful in what they can do.
dnsmasq is (i think) newer and more limited in what it can do. However it's probably good enough for the average home user and probably a lot easier to configure for operation on a small network (one or two small subnets).
Here, I chose ISC DHCP server. It's more powerful and, welp, that's what Ubuntu
documentation uses. This was also a good learning opportunity, since I'm kinda
already used to dnsmasq
because of VM stuffs.
https://ubuntu.com/server/docs/network-dhcp
https://www.raspberrypi.org/forums/viewtopic.php?t=182032
http://manpages.ubuntu.com/manpages/cosmic/man5/netplan.5.html
Let's install the daemon:
sudo apt install isc-dhcp-server
... and configure it:
vi /etc/dhcp/dhcpd.conf
... like this:
default-lease-time 600;
max-lease-time 7200;
subnet 192.168.111.0 netmask 255.255.255.0 {
range 192.168.111.10 192.168.111.200;
}
Note that I don't use IPv6 in this specific case, so isc-dhcp-server6.service
is disabled, and /etc/dhcp/dhcpd6.conf
will not be used.
Interestingly, the list of interfaces to listen to is separately stored in
/etc/default/isc-dhcp-server
. I edited the file to let the daemon listen to
only the 2.5GBE interface.
It's also necessary to update the network settings to match the above config. Specifically, the target interface must have a valid address in the subnet specified above.
I used netplan
to make this change. The following config is added to
/etc/netplan
:
network:
version: 2
ethernets:
eth0:
match:
macaddress: xx:xx:xx:xx:xx:xx # Fill in this value
set-name: eth0
# these values are tied to DHCP server settings
addresses: [192.168.111.1/24]
.. and run this to apply the config:
sudo netplan apply
On the client side, configure the network interface to use DHCP. It'll now fetch a new IP address automatically.
Unfortunately, this turned out to be not enough for me. I want to use human-readable names instead of directly punching in IP addresses. mDNS might be a solution.