Improve Knot resolver to take into account multiple dnsmasq instances

Hi,

I wanted to acomplish multiple DNS local search domains in my home/lab network. But I bumped into hardcoded thing in Knot Resolver scripts. Particulary /etc/resolver/dhcp_host_domain_ng.py there is line:
self.__local_suffix = uci_get("dhcp.@dnsmasq[0].local").replace( [...]
So it takes into consideration only first entry/instance of dnsmasq.

I would like to have different subdomains/search domains for my networks with multiple dnsmasq instances for each network. And still would like to use “Use DHCP clients in DNS” option. To explain I would like it to parse thruu all entries and put that into DNS. So also:
self.__local_suffix = uci_get("dhcp.@dnsmasq[1-9999999].local").replace( etc.

So when I have:

dhcp.@dnsmasq[0].local='/lan/'
And
dhcp.@dnsmasq[1].local='/otherlocaldomain/'

This will still work. And merge all entries into resolver.

FYI: @vcunat

You want every machine’s name copied to multiple (sub)domains? Sounds weird to me, but it’s not like I’m an expert on DHCP-related stuff.

Ah, probably for every network separately? I’m not sure if the hook even lets the script know in some way which network caused the event.

Not each one in every zone. I have IOT zone with dnsmasq serving only that interface and with static+dynamic leases only for that zone. And separate dnsmasq instance for other network/s serving only that other particular zone and interface.

I am experimenting with configuration now. And it should parse something like that

/etc/config/dhcp
config dnsmasq
    DEFAULT INSTANCE OPTIONS /lan/

And another entry of dnsmasq with or without name so another:

config dnsmasq
    OPTIONS FOR SECOND INSTANCE /iot/

Resulting in:

root@router:~# uci show dhcp | grep ".local"
dhcp.@dnsmasq[0].local=/lan/
dhcp.@dnsmasq[1].local=/iot/

Or config created in LuCi with a name assigned to it so:

config dnsmasq 'iot'
    OPTIONS FOR SECOND INSTANCE /iot/

Resulting in:

root@router:~# uci show dhcp | grep ".local"
dhcp.@dnsmasq[0].local=/lan/
dhcp.iot.local=/iot/

I guess it could be done by simple if checking if there is more than one instance. If there is only one then code as is. And else parse thru each instance and merge that to resolver. Honoring config with and without name so some regexp. Because now the value of dhcp_leases file is hardcoded to @dnsmasq[0] so first instance even without name. So also when someone would like to put a name to config it will also break “Use DHCP Clients in DNS” option in Reforis

If I would use vanilla OpenWRT with dnsmasq for DNS there would be no problem. But I like somehow Knot Resolver. But well the dhcp_host_domain_ng.py is a bit hacky taking into consideration just basic and one possible config.

It doesnt its hardcoded uci value for that which is bad practice.

But that’s not (all) what it does. It reacts to individual events when an address is added or removed. And right now I don’t see the events passing which network is affected. (just mac, IP and name)

You could have a separate (wrapper) script per interface, but that’s ugly. Or forward those particular DNS requests to dnsmasq (as some other users posted here for various reasons) instead of transplanting the name bindings into kresd.

Ok so maybe I will explain background how I bumped into this.

I have HomeAssistant on separate machine. With two network interfaces in two VLANs.

Let’s say:

homeassistant.lan 192.168.1.23/24
homeassistant.lan 192.168.2.23/24

And I have static leases in dnsmasq. So when any client want to reach homeassistant.LAN (because there is only one local search domain it gets two IP addresses from Knot. And my goal is:

homeassistant.iot.tld 192.168.1.23/24
homeassistant.lan.tld 192.168.2.23/24

So clients in iot network will get only IP address from that particular network not both. Because now it just round-robin on two IPs and causes routing issues. I worked it around by using IPs instead of names to connect. But well I am not a robot so I prefer using names.

I am ofc open to some other solution for that particular problem if someone has an idea. Just to note forwarding between zones is denied by default so it depend which IP is returned first by resolving name. And the connection works or not.

Ok I’ve found better way. HomeAssistant advertize its service via mDNS.
So I just used homeassistant.local and mDNS doesnt traverse pass network segment so its going to work in each network. But well hacky scripts with hardcoded values is not the way to go for Knot Resolver.

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.