[Dnsmasq-discuss] dnsmasq command to add dhcp-host record?
Jelle de Jong
jelledejong at powercraft.nl
Wed Jan 6 20:00:12 GMT 2021
On 1/6/21 7:29 PM, After Sales wrote:
> On Sun, Jan 03, 2021 at 09:46:51PM +0100, Geert Stappers wrote:
>> On Sun, Jan 03, 2021 at 09:03:57PM +0100, Jelle de Jong wrote:
>>> What is a good way to dynamically add a dhcp-host record, so a machine will
>>> get the ipaddr I assign to it?
>>>
>>> example:
>>> dhcp-host=52:54:00:e6:f4:8a,192.168.40.29,nginx01.example.lan,infinite
>>>
>>> I want to automate the process and be able to integrate it with my ansible
>>> deployment systems.
>>>
>>> Adding the line to the dnsmasq config file and reloading it will do the
>>> trick but is there a way to dynamically add it with some dnsmasq command?
>>>
>>> Tips?
>>
>> Quoting the manual page
>>
>> --dhcp-hostsdir=<path>
>> This is equivalent to --dhcp-hostsfile, except for the following. The path MUST be
>> a directory, and not an individual file. Changed or new files within the directory
>> are read automatically, without the need to send SIGHUP. If a file is deleted or
>> changed after it has been read by dnsmasq, then the host record it contained will
>> remain until dnsmasq receives a SIGHUP, or is restarted; ie host records are only
>> added dynamically.
>>
>
> Does it fit your needs?
Well... issues... again...
TL;DR please add a dnsmasq delay after a inotify event trigger to
actually read the file... and please add option to remove host as well
at inotify watch event.
dhcp-hostsdir=/etc/dnsmasq.d/dhcp
hostsdir=/etc/wireguard
- name: create /etc/dnsmasq.d/dhcp/ directory if it does not exist with
parents
file:
path: /etc/dnsmasq.d/dhcp/
state: directory
delegate_to: "{{ dnsmasq }}"
tags: dnsmasq
- name: creating a file with content
/etc/dnsmasq.d/dhcp/{{inventory_hostname}}.conf
copy:
dest: "/etc/dnsmasq.d/dhcp/{{inventory_hostname}}.conf"
content: |
{{mac.stdout}},{{ipaddr}},{{inventory_hostname}}
mode: 0644
owner: root
delegate_to: "{{ dnsmasq }}"
when: ipaddr is defined and inventory_hostname in groups.virtual
tags: dnsmasq
dnsmasq inotify is trigger happy and it would be nice to have a second
or so delay in the actual re-scanning, that would help a lot...
currently when ansible places the file dnsmasq tries to read the config
file, but the content is not always there yet and then it is messed up.
dhcp-host=52:54:00:ce:02:48,192.168.25.32,samba09.powercraft.lan,infinite
I was first using the infinite part to have a more static lease, but
especially when I want to change the IP later. I have to manually stop
the service remove it from the /var/lib../lease file and start dnsmasq
again. Thankfully removing the infinite part makes it more flexible now.
and it is working most of the times...
I got the same issue with the hostsdir system ... but when I need to
dynamical remove hosts and have to reload dnsmasq. I wrote a bash script
that checks if a host got removed and then reloads the dnsmasq systemd,
however on my busy network +100 systems dnsmasq got reloaded often
sometimes every second, and it seems dnsmasq does not like this so much
and sometimes gets into a state where it needs a complete reboot to be
able to have working DNS resolving again.
I need to rewrite the scripts to work in some notification bus and
collects the reloads and only do them every minute or so if they
happen... possible workaround is to to just have dnsmasq reload every
minute, despite any host changes, but this sounds just wrong to do...
Kind regards,
Jelle de Jong
More information about the Dnsmasq-discuss
mailing list