[Dnsmasq-discuss] DNS from dhcp-host while client is offline, generate config files

Geert Stappers stappers at stappers.nl
Fri Oct 8 20:13:36 UTC 2021


On Fri, Oct 08, 2021 at 10:28:07PM +0300, Alkis Georgopoulos wrote:
> On 10/8/21 10:12 PM, Olaf Hering wrote:
> > Am Fri, 8 Oct 2021 19:02:31 +0300
> > schrieb Alkis Georgopoulos <alkisg at gmail.com>:
> > 
> > > yeah I too settled for a sed command
> > 
> > Sorry, I do not use sed or anything.
> > 
> > If the MAC/ip/hostname triple is know in advance, create a static config
> > file with host-record= and dhcp-host=. Sorry if that was unclear.
> > 
> > But if you have a solution that you understand and that appears to work for
> > you, go for it.
> 
> I meant that you too generate the dnsmasq configuration files.
> I.e. a script or a generation command is involved.
> 
> In your example, you maintained your information as a series of shell
> variable assignments (e.g. `dnsdomain=home.arpa`).
> Then you used the `tee` command to generate a dnsmasq configuration file for
> a single client.
> I assume that for many clients, you'd use a loop.
> 
> Using the sed command is similar although simpler as it avoids the need for
> a loop. I use it like this:
> 
> 1) I maintain all our information in a dhcp-hosts.csv file like the
> following:
> 
> ac:22:0b:c5:9f:fb,set:ltsp0a1,10.0.1.31,g01pc01
> ac:22:0b:2b:df:ba,set:ltsp0a1,10.0.1.32,g01pc02
> 
> This is already a valid dnsmasq configuration file.

Nice.

Thanks for making me realizing that a `.csv` can be configuration file.
 

> 2) After editing that file, I run the following command to convert it to an
> addn-hosts.csv file:
> 
> sed -n 's/.*,\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\),\([-a-z0-9]*\).*/\1\t\2/p' dhcp-hosts.csv > addn-hosts.csv

That same line at multiple physical lines and the `-n` being documented:

  sed --silent \
    's/.*,\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\),\([-a-z0-9]*\).*/\1\t\2/p' \
    dhcp-hosts.csv > addn-hosts.csv

 
> So that way, we maintain a single dhcp-hosts.csv file, and we run a single
> command to create the respective addn-hosts.csv file.
> Dnsmasq then uses both of these configuration files.
> 
> Thank you for your time!

Thank you for sharing the sed script that was mentioned two or three
postings by you earlier.  It is now in the mailinglist archive.


> Alkis



Groeten
Geert Stappers
-- 
Silence is hard to parse



More information about the Dnsmasq-discuss mailing list