New Member
Posts: 9
Registered: ‎04-28-2013
Accepted Solution

Conditional DNS forwarding with dnsmasq

Hi,

 

I'd like to add the equivalent of:

server=/remote.local/10.0.0.10

 

to dnsmasq.conf to allow for conditional DNS forwarding. Is that possible to do via a "set" command?

 

I assume that if I manually change the config file it wont be included in any backup/restore operations.

 


Accepted Solutions
Ubiquiti Employee
Posts: 2,991
Registered: ‎02-04-2013
Kudos: 354
Solutions: 289

Re: Conditional DNS forwarding with dnsmasq

[ Edited ]

The CLI doesn't support this currently, however you can try the two patches logged below -

 

root@dut1:~# cat dns_forwarding.orig.patch 
--- /dev/null
+++ /opt/vyatta/share/vyatta-cfg/templates/service/dns/forwarding/options/node.def
@@ -0,0 +1,7 @@
+multi:
+type: txt
+# help formatted below to appear properly during tab completion
+help: Additional options for dns forwarding. You must 
+                use the syntax of dnsmasq.conf in this text-field. Using this 
+               without proper knowledge may result in a crashed dnsmaq daemon.
+               Check system log to look for errors.
root@dut1:~# 
root@dut1:~# cat vyatta-dns-forwarding.pl.orig.patch 
--- /opt/vyatta/sbin/vyatta-dns-forwarding.pl.orig
+++ /opt/vyatta/sbin/vyatta-dns-forwarding.pl
@@ -63,7 +63,7 @@
     my $output = '';
     my $config = new Vyatta::Config;
     my $use_dnsmasq_conf = 0;
-    my (@listen_interfaces, $cache_size, @use_nameservers, $use_system_nameservers, @use_dhcp_nameservers);
+    my (@listen_interfaces, $cache_size, @use_nameservers, $use_system_nameservers, @use_dhcp_nameservers, @options);
 
     $config->setLevel("service dns forwarding");
 
@@ -73,6 +73,7 @@
            @use_nameservers = $config->returnOrigValues("name-server");
            $use_system_nameservers = $config->existsOrig("system");
            @use_dhcp_nameservers = $config->returnOrigValues("dhcp");
+           @options = $config->returnOrigValues("options");
 
     } else {
            @listen_interfaces = $config->returnValues("listen-on");
@@ -80,6 +81,7 @@
            @use_nameservers = $config->returnValues("name-server");
            $use_system_nameservers = $config->exists("system");
           @use_dhcp_nameservers = $config->returnValues("dhcp");
+          @options = $config->returnValues("options");
     }
 
     if (@listen_interfaces != 0) {
@@ -130,6 +132,12 @@
                }
            } 
         }
+    }
+
+    if (@options != 0) {
+       foreach my $option (@options) {
+          $output .= "$option\n";
+       }
     }
 
     if ($use_dnsmasq_conf == 1) {
root@dut1:~# 

then try -

 

root@dut1:~# exit
logout
[edit]
ubnt@dut1# grep server /etc/dnsmasq.conf
[edit]
ubnt@dut1# set service dns forwarding options "server=/remote.local/10.0.0.10"
[edit]
ubnt@dut1# set service dns forwarding options "server=/abc.local/10.0.1.10"
[edit]
ubnt@dut1# 
[edit]
ubnt@dut1# compare
[edit service dns forwarding]
+options server=/remote.local/10.0.0.10
+options server=/abc.local/10.0.1.10
[edit]
ubnt@dut1# commit
[edit]
ubnt@dut1# grep server /etc/dnsmasq.conf
server=/remote.local/10.0.0.10
server=/abc.local/10.0.1.10
[edit]
ubnt@dut1# delete service dns forwarding options 
[edit]
ubnt@dut1# commit
[edit]
ubnt@dut1# grep server /etc/dnsmasq.conf
[edit]
ubnt@dut1# 
[edit]

 

 

View solution in original post


All Replies
Ubiquiti Employee
Posts: 2,991
Registered: ‎02-04-2013
Kudos: 354
Solutions: 289

Re: Conditional DNS forwarding with dnsmasq

[ Edited ]

The CLI doesn't support this currently, however you can try the two patches logged below -

 

root@dut1:~# cat dns_forwarding.orig.patch 
--- /dev/null
+++ /opt/vyatta/share/vyatta-cfg/templates/service/dns/forwarding/options/node.def
@@ -0,0 +1,7 @@
+multi:
+type: txt
+# help formatted below to appear properly during tab completion
+help: Additional options for dns forwarding. You must 
+                use the syntax of dnsmasq.conf in this text-field. Using this 
+               without proper knowledge may result in a crashed dnsmaq daemon.
+               Check system log to look for errors.
root@dut1:~# 
root@dut1:~# cat vyatta-dns-forwarding.pl.orig.patch 
--- /opt/vyatta/sbin/vyatta-dns-forwarding.pl.orig
+++ /opt/vyatta/sbin/vyatta-dns-forwarding.pl
@@ -63,7 +63,7 @@
     my $output = '';
     my $config = new Vyatta::Config;
     my $use_dnsmasq_conf = 0;
-    my (@listen_interfaces, $cache_size, @use_nameservers, $use_system_nameservers, @use_dhcp_nameservers);
+    my (@listen_interfaces, $cache_size, @use_nameservers, $use_system_nameservers, @use_dhcp_nameservers, @options);
 
     $config->setLevel("service dns forwarding");
 
@@ -73,6 +73,7 @@
            @use_nameservers = $config->returnOrigValues("name-server");
            $use_system_nameservers = $config->existsOrig("system");
            @use_dhcp_nameservers = $config->returnOrigValues("dhcp");
+           @options = $config->returnOrigValues("options");
 
     } else {
            @listen_interfaces = $config->returnValues("listen-on");
@@ -80,6 +81,7 @@
            @use_nameservers = $config->returnValues("name-server");
            $use_system_nameservers = $config->exists("system");
           @use_dhcp_nameservers = $config->returnValues("dhcp");
+          @options = $config->returnValues("options");
     }
 
     if (@listen_interfaces != 0) {
@@ -130,6 +132,12 @@
                }
            } 
         }
+    }
+
+    if (@options != 0) {
+       foreach my $option (@options) {
+          $output .= "$option\n";
+       }
     }
 
     if ($use_dnsmasq_conf == 1) {
root@dut1:~# 

then try -

 

root@dut1:~# exit
logout
[edit]
ubnt@dut1# grep server /etc/dnsmasq.conf
[edit]
ubnt@dut1# set service dns forwarding options "server=/remote.local/10.0.0.10"
[edit]
ubnt@dut1# set service dns forwarding options "server=/abc.local/10.0.1.10"
[edit]
ubnt@dut1# 
[edit]
ubnt@dut1# compare
[edit service dns forwarding]
+options server=/remote.local/10.0.0.10
+options server=/abc.local/10.0.1.10
[edit]
ubnt@dut1# commit
[edit]
ubnt@dut1# grep server /etc/dnsmasq.conf
server=/remote.local/10.0.0.10
server=/abc.local/10.0.1.10
[edit]
ubnt@dut1# delete service dns forwarding options 
[edit]
ubnt@dut1# commit
[edit]
ubnt@dut1# grep server /etc/dnsmasq.conf
[edit]
ubnt@dut1# 
[edit]

 

 

New Member
Posts: 9
Registered: ‎04-28-2013

Re: Conditional DNS forwarding with dnsmasq

Looks awesome. Will try it out during the week.

 

Any chance it'll get added to a future firmware update?

 

Previous Employee
Posts: 13,551
Registered: ‎06-10-2011
Kudos: 5474
Solutions: 1656
Contributions: 2

Re: Conditional DNS forwarding with dnsmasq

Yeah we will do some more testing and may be able to include this in the next release.

New Member
Posts: 9
Registered: ‎04-28-2013

Re: Conditional DNS forwarding with dnsmasq

Great, thanks a lot.
Previous Employee
Posts: 10,504
Registered: ‎06-09-2011
Kudos: 3141
Solutions: 945
Contributions: 16

Re: Conditional DNS forwarding with dnsmasq

If you're interested in more advanced features of dnsmasq, this patch covers lots of them: dnsmasq patch

EdgeMAX Router Software Development
Member
Posts: 129
Registered: ‎04-24-2013
Kudos: 34
Solutions: 2

Re: Conditional DNS forwarding with dnsmasq

Patch works great. Thanks.

Member
Posts: 129
Registered: ‎04-24-2013
Kudos: 34
Solutions: 2

Re: Conditional DNS forwarding with dnsmasq

Can this be added for the 1.2.0 release? TIA.

Ubiquiti Employee
Posts: 2,991
Registered: ‎02-04-2013
Kudos: 354
Solutions: 289

Re: Conditional DNS forwarding with dnsmasq


@wkweksl wrote:

Can this be added for the 1.2.0 release? TIA.


Yes, It's already in.