Automatically populating DNS from DHCP static leases?

dns

#1

My local network uses DHCP. I’m trying to set up local names and static addresses for some well-known devices.

This appears to be a bit of a morass because it seems that most of the DNS settings only apply to dnsmasq, but the main DNS resolver is kresd (this could use some UI improvements)… however, I’ve made it work:

But only by entering all the information twice: once in the DHCP static leases page, and then I have to enter all the hostname/IP information again in the Hostnames page. (All in Luci, as none of this appears configurable in Foris.)

Am I missing some way of automatically populating DNS with the information from the static leases? It would make setting up new devices far easier.

(There’s an option in Foris to do just this, but it doesn’t seem to do anything.)


#2

This is done automatically, though only for ipv4 in conjunction with dnsmasq (not working with ipv6/odhcpd) , by https://gitlab.labs.nic.cz/turris/turris-os-packages/blob/v3.11.2/net/resolver-conf/files/dhcp_host_domain_ng.py

Perhaps you could describe the symptom of what is not working as it is not so apparent from the post.


That should not be necessary.


Foris is not meant as a replacement for LuCI, there is a distinctive difference in the user type being served by each frontend respectively. That said it could be confusing at times in view of settings overlapping amongst the 2 frontends.


#3

Well, the symptom is as described — I enter hostname, mac address and IP address into the DHCP configuration page, and then even though the device gets assigned the correct IP address by DHCP, DNS lookups don’t resolve the hostnames to the IP address.

If this is configuring dnsmasq only, then how could I verify that kresd is forwarding requests to dnsmasq?


#4

I am not sure whether changing dnsmasq DHCP settings in LuCI is actually invoking a reload of the resolver or just dnsmasq (and thus missing to kick off dhcp_host_domain_ng.py)

Try from ssh cli /etc/init.d/resolver reload or /etc/init.d/resolver restart which kicks off dhcp_host_domain_ng.py


To my understanding it is not forwarding but the script is adding host files to kresd by parsing the config settings in dhcp

def refresh_leases(self):
        self._clean_hints()
        if self.__static_leases_enabled:
            self._call_kresd("hints.add_hosts('%s')" % self.__static_leases)
        if self.__dynamic_leases_enabled:
            self._call_kresd("hints.add_hosts('%s')" % self.__dynamic_leases)

#5

I would do it differently:
Try this, for example. If you are interested in a static reservation, do the following:
https://doc.turris.cz/doc/en/public/dns_knot_misc#adding_static_address_records

Edit your file and enter information here:
/etc/hosts


#6

@n8v8r: I’ve been rebooting to make sure that any configuration changes take effect.

@RomanHK: that doesn’t do what I want it to do. I want to configure DHCP and DNS in a single place. Editing /etc/hosts (which I’ve actually also tried, along with editing /etc/ethers) will still require me to enter the hostnames and IP addresses twice.


#7

I have to throw in the towel here as not being familiar with kresd. The script works as expected for unbound, i.e. only having entered static leases in LuCI. That was until having switched to odhcpd which is not supported by the script, but that is a different story then.


#8

Well, thanks for trying anyway…

I haven’t done any customisation of my system; this is as it shipped. Is this all supposed to work out of the box? I came here from DD-WRT, where this kind of configuration is very easy.


#9

Unfortunately, it did not work otherwise. When I have enabled DNS in Foris, a domain (lan) is required, so the result was: computer1.lan or computer2.lan

To do this all in one place, we (the users) will not do anything about it. It’s up to developers to do it.


#10

I hope so :slight_smile:

… that dynamic script need some revision. There is another issue with format of lease files, script is complaining about it since two updates of TOS back (i did not changed anything).
Now have to use static leases for some “important” devices in my network in combination of hostname entries using Luci. And so far all of them are getting my local dns ips.
Populating DNS, … chmmm, it is a bit tricky as it is not just one place but three, to trigger it. I think i have it working with localdomain and static leases. Let me check my setup (tomorrow possibly), i will try to give more specific hints …


#11

So here it is. Hope it helps.

mysetup

http://192.168.1.1/foris/config/main/dns/

  • use forwarding: no
  • disable dnssec: no
  • enable dhcp clienst in dns: yes
  • domain of dhcp clients in dns : mydomain.lan
    http://192.168.1.1/cgi-bin/luci/admin/network/hosts
  • enter hostname for each client names (without mydomain.lan part)
    http://192.168.1.1/cgi-bin/luci/admin/network/dhcp
    (general settings)
  • domain required : yes
  • local server : /mydomain.lan/
  • local domains : mydomain.lan
  • dns forwarding : list-of-you-favorite-dns-servers
    (resolv and hosts files)
  • use /etc/ethers : no
  • leasefiles: /path/to/dhcp.leases
  • ignore resolve file: yes
  • ignore /etc/hosts : yes
    (static leases)
  • define entry for each “hostname” , exactly same strings without mydomain.lan string
    (advanced settings)
  • expand hosts: no
  • strict order: yes
    http://192.168.1.1/cgi-bin/luci//admin/network/network/lan/
    (DHCP Server: advanced settings )
  • dynamic dhcp : yes
  • force : yes
  • dhcp-options: “6,192.168.1.1,192.168.1.2”
    http://192.168.1.1/cgi-bin/luci//admin/network/network/wan/
    (advanced settings)
  • bring up on boot: yes
  • use default gateway : yes
  • use dns servers advertised by peer: no
  • use custom dns servers : list-of-your-favorite-dns-servers

And in some uci configs (dhcp,resolver) i have to check and setup static/dynamic domain parameter(and value) explicitly for each configuration block/resolver.


#12

In Foris you can choose the suffix. It doesn’t let you choose an empty one, though. In any case, I personally don’t think leaving an empty one would be a good idea.

For me the names from DHCP just work out of the box, after clicking that single checkbox in Foris.


#13

If you want to track down what’s wrong, you can inspect an “in-between” place: /tmp/dhcp.leases.dynamic

EDIT: well, I’ve only tested all this with “dynamic leases” actually so far.


#14

Hosts from DHCP to DNS. Need to set static DHCP:
add to /etc/config/dhcp host

config host
option tag ‘lan’ <— tag of lan static host
option name ‘dgw’
option mac ‘00:09:b0:xx:xx:x’
option ip ‘192.168.1.1’

and domain my config dnsmasq:
(hosts add from LuciGIU [DHCP and DNS] but without option tag ‘lan’ :frowning: )

config dnsmasq
option domainneeded ‘1’
option boguspriv ‘1’
option localise_queries ‘1’
option rebind_protection ‘1’
option rebind_localhost ‘1’
option local ‘/domena.com/’
option domain ‘domena.com
option expandhosts ‘1’
option authoritative ‘1’
option readethers ‘1’
option leasefile ‘/tmp/dhcp.leases’
option resolvfile ‘/tmp/resolv.conf.auto’
option port ‘0’
option localservice ‘1’
option quietdhcp ‘1’
option nonwildcard ‘1’
list interface ‘br-lan’

in /etc/dnsmasg.conf you add:
#pool for non static users
dhcp-range=tag:!known,lan,192.168.1.200,192.168.1.254,2m

/etc/init.d/dnsmasq restart

and DNS now:

ping dgw
PING iradiow (192.168.1.1): 56 data bytes
64 bytes from 192.168.1.1: seq=0 ttl=60 time=6.887 ms

ping dgw.domena.com
PING dgw.domena.com (192.168.1.1): 56 data bytes
64 bytes from 192.168.1.1: seq=0 ttl=64 time=0.093 ms

nslookup dgw.domena.com
Server: 127.0.0.1
Address: 127.0.0.1#53
Name: dgw.domena.com
Address 1: 192.168.1.1
*** Can’t find dgw.domena.com: No answer

nslookup 192.168.1.1
Server: 127.0.0.1
Address: 127.0.0.1#53
** server can’t find 1.1.168.192.in-addr.arpa: NXDOMAIN

DNS kresd no reverse DNS set.

nslookup dgw.piesok.com
Server: 127.0.0.1
Address: 127.0.0.1#53
Name: dgw.piesok.com
Address 1: 192.168.1.1
*** Can’t find dgw.piesok.com: No answer <---- no ipv6

I set no ipv6 used!

pls look to /var/kresd/hints.tmp.
All static users.