Discussion:
[Dnsmasq-discuss] Using a variable in the address option in dnsmasq.conf
Steve Lloyd
2018-02-19 20:28:52 UTC
Permalink
Is it possilbe to set a variable and then use it as follows? or is there a
way to set and use a variable in the conf file for address entries?

myip=10.0.1.6
address=/2o7.net/$myip
address=/2mdm.net/$myip

instead of
address=/2o7.net/10.0.1.6
address=/2mdm.net/10.0.1.6
M. Buecher
2018-02-20 07:44:46 UTC
Permalink
Is it possilbe to set a variable and then use it as follows? or is there a way to set and use a variable in the conf file for address entries?
myip=10.0.1.6
address=/2o7.net/$myip [1]
address=/2mdm.net/$myip [2]
instead of
address=/2o7.net/10.0.1.6 [3]
address=/2mdm.net/10.0.1.6 [4]
+1 for such a feature as this would easy my playground setup a lot, in
my case:
dhcp-host=aa:bb:cc:dd:ee:ff,${NETWORK4NET1PREFIX}.27,[${NETWORK6ULA1PREFIX}::1b],my-host



Links:
------
[1] http://2o7.net/$myip
[2] http://2mdm.net/$myip
[3] http://2o7.net/10.0.1.6
[4] http://2mdm.net/10.0.1.6
Petr Menšík
2018-03-02 12:46:06 UTC
Permalink
You can use any script to generate those addresses into separate file.
Dnsmasq is very low overhead server without real built-in scripting for
these things. It already contains lua interpreter, but I think such
features should be left to external scripts instead.

You can already use:
conf-dir=/etc/dnsmasq.d

and then generate your file any way you need. For example in bash

echo "# Autogenerated file, do not edit by hand" >
/etc/dnsmasq.d/blocked.conf
for DOMAIN in 2o7.net 2mdm.net
do echo "address=/$DOMAIN/$MYIP" >> /etc/dnsmasq.d/blocked.conf
done

I think this is simple enough for any reasonable use. Why should dnsmasq
have it built-in?
Post by M. Buecher
Is it possilbe to set a variable and then use it as follows?  or is
there a way to set and use a variable in the conf file for address
entries?
 
myip=10.0.1.6
address=/2o7.net/$myip <http://2o7.net/$myip>
address=/2mdm.net/$myip <http://2mdm.net/$myip>
 
instead of 
address=/2o7.net/10.0.1.6 <http://2o7.net/10.0.1.6>
address=/2mdm.net/10.0.1.6 <http://2mdm.net/10.0.1.6>
 
 
+1 for such a feature as this would easy my playground setup a lot, in
dhcp-host=aa:bb:cc:dd:ee:ff,${NETWORK4NET1PREFIX}.27,[${NETWORK6ULA1PREFIX}::1b],my-host
 
_______________________________________________
Dnsmasq-discuss mailing list
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss
--
Petr Menšík
Software Engineer
Red Hat, http://www.redhat.com/
email: ***@redhat.com PGP: 65C6C973
w***@gmail.com
2018-03-02 17:23:54 UTC
Permalink
Post by Petr Menšík
and then generate your file any way you need. For example in bash
echo "# Autogenerated file, do not edit by hand" >
/etc/dnsmasq.d/blocked.conf
for DOMAIN in 2o7.net 2mdm.net
do echo "address=/$DOMAIN/$MYIP" >> /etc/dnsmasq.d/blocked.conf
done
even better would be...


echo "# Autogenerated file, do not edit by hand" > /etc/dnsmasq.d/blocked.conf
for DOMAIN in 2o7.net 2mdm.net facebook.com fbcdn.net fbcdn.com facebook.net
do echo "server=/$DOMAIN/" >> /etc/dnsmasq.d/blocked.conf
done


so dnsmasq will return NXDOMAIN for blocked domains :evilBOFHgrin:
--
NOTE: No off-list assistance is given without prior approval.
*Please keep mailing list traffic on the list unless*
*a signed and pre-paid contract is in effect with us.*
Steve Lloyd
2018-03-02 18:56:45 UTC
Permalink
If I update an external conf file will dnsmasq read in the changes in real
time or do I have to restart it?
Post by w***@gmail.com
Post by Petr Menšík
and then generate your file any way you need. For example in bash
echo "# Autogenerated file, do not edit by hand" >
/etc/dnsmasq.d/blocked.conf
for DOMAIN in 2o7.net 2mdm.net
do echo "address=/$DOMAIN/$MYIP" >> /etc/dnsmasq.d/blocked.conf
done
even better would be...
echo "# Autogenerated file, do not edit by hand" >
/etc/dnsmasq.d/blocked.conf
for DOMAIN in 2o7.net 2mdm.net facebook.com fbcdn.net fbcdn.com facebook.net
do echo "server=/$DOMAIN/" >> /etc/dnsmasq.d/blocked.conf
done
--
NOTE: No off-list assistance is given without prior approval.
*Please keep mailing list traffic on the list unless*
*a signed and pre-paid contract is in effect with us.*
_______________________________________________
Dnsmasq-discuss mailing list
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss
Petr Menšík
2018-03-05 09:45:15 UTC
Permalink
Any changes will not be read real time, only selected files like
--dhcp-hostsdir or --hostsdir. I think --hostsdir could be used for it,
reloading it without explicit SIGHUP. It will just watch for changes in
that directory. It would not allow to remove already served names
however. I think you can only add new names. I did not verify that
however myself.
Post by Steve Lloyd
If I update an external conf file will dnsmasq read in the changes in
real time or do I have to restart it?
Post by Petr Menšík
and then generate your file any way you need. For example in bash
echo "# Autogenerated file, do not edit by hand" >
/etc/dnsmasq.d/blocked.conf
for DOMAIN in 2o7.net <http://2o7.net> 2mdm.net <http://2mdm.net>
    do echo "address=/$DOMAIN/$MYIP" >> /etc/dnsmasq.d/blocked.conf
done
even better would be...
echo "# Autogenerated file, do not edit by hand" >
/etc/dnsmasq.d/blocked.conf
for DOMAIN in 2o7.net <http://2o7.net> 2mdm.net <http://2mdm.net>
facebook.com <http://facebook.com> fbcdn.net <http://fbcdn.net>
fbcdn.com <http://fbcdn.com> facebook.net <http://facebook.net>
   do echo "server=/$DOMAIN/" >> /etc/dnsmasq.d/blocked.conf
done
--
  NOTE: No off-list assistance is given without prior approval.
        *Please keep mailing list traffic on the list unless*
        *a signed and pre-paid contract is in effect with us.*
_______________________________________________
Dnsmasq-discuss mailing list
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss
_______________________________________________
Dnsmasq-discuss mailing list
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss
--
Petr Menšík
Software Engineer
Red Hat, http://www.redhat.com/
email: ***@redhat.com PGP: 65C6C973
Loading...