QNAP custom dhcpd config file

In some network I wanted to use QNAP nas (QTS 4.3.4 x64) also as DHCP server, but with my own config file. I needed static bindings and special config with cookie for Smart-UPS RT 10000 XL (which I already mentioned here).
First option was to use some App from AppCenter like DNSMasq (not seen that app? 🙂 You can use alternative repo like https://www.qnapclub.eu/pl/repo/xml – maybe I’ll write something more about that some day), but in my case the default volume is encrypted. As long as I don’t enter password manually after restart or a power failure apps won’t get loaded, so network is dead without DHCP server.
Some solution is to make special not encrypted volume only with that app – but unfortunately most apps does not support volume migration (some other time I will write something more about how to enable this option).
The third solution is to use system dhcp server which is ISC DHCP. It is loaded even when main volume is not mounted. But how to provide custom config premanently?

First of all we need to enable dhcp server in Network & Virtual switch app. In my case br0 interface was used. I propose to configure as small IP range as possible in case if some client succeed to connect before we replace config (just one IP would be fine). Then we put our config file in

/etc/config/dhcpd_br0.conf

For my UPS it was something like:

#custom_config
ddns-update-style none;
get-lease-hostnames true;
default-lease-time 7200;                                                                                                                                                     
max-lease-time 7200;
log-facility local7;
ping-check false;
option apc-token code 43 = string;
authoritative;

subnet 192.168.1.0 netmask 255.255.255.0 {
    option domain-name "domain.org";
    option domain-name-servers 8.8.8.8, 8.8.4.4;
    option routers 192.168.1.1;
    option subnet-mask 255.255.255.0;
    option broadcast-address 192.168.1.255;
    range 192.168.1.71 192.168.1.90;
}

#some static host
host hsot1 {
   fixed-address 192.168.1.2;
   hardware ethernet 04:14:a6:c9:66:78;
}

#Smart-UPS RT 10000 XL  with AP9619 card 
host ups {
   fixed-address 192.168.1.13;
   hardware ethernet 00:ca:a7:62:37:64;
   #cookie needed to get things work
   option apc-token 01:04:31:41:50:43;
}

Then we create

/etc/config/dhcpd_check

file:

#!/bin/sh

/bin/grep -q custom_config /etc/dhcpd_br0.conf || \
    ( cp -f /etc/config/dhcpd_br0.conf /etc/dhcpd_br0.conf && \
    kill `cat /mnt/ext/opt/netmgr/api/core/dhcpdLink/br0.pid` )

That script checks if the current config file is ours. If not it replaces the file and kills dhcpd server. QTS has some kind of watchdog mechanism so we don’t need to bother to start it again (ISC DHCP does not support config reload with signals so more elegant way is not possible 🙁 ). Please remember to set correct permissions by

chmod 700 /etc/config/dhcpd_check

Last thing to do is to add our script to cron by editing

/etc/config/crontab

and adding

* * * * * /etc/config/./dhcpd_check

Not very elegant solution, but works 🙂

One Reply to “QNAP custom dhcpd config file”

Leave a Reply to EllPape Cancel reply

Your email address will not be published.