[OpenWrt-Devel] Alternative DNS servers for DHCP static clients in Luci?

Mikael Bak mbak at fxnet.hu
Sun Feb 3 07:12:33 EST 2019


Hi,

On 2019. 01. 09. 16:18, A. Benz wrote:
> Hi,
> 
> I setup something similar to what you're trying to do, basically:
> 
> 1. Create another dnsmasq instance with the desired DNS servers for 
> static/known clients. You do this by editing /etc/config/dhcp, like so:
> 
> config dnsmasq 'main'
>      option domainneeded '1'
>      <snip>
>      list server '208.67.222.222'
>      list server '208.67.220.220'
>      option localservice '1'
> 
> config dnsmasq 'secondary'
>      <snip>
>      option resolvfile '/tmp/resolv.conf.auto'
>      option port '5353'            <--------- Note we specify port so it 
> won't conflict with 'main' dnsmasq instance.
>      option localservice '1'
> 
> config dhcp 'lan'
>      option interface 'lan'
>      option start '100'
>      option limit '150'
>      option leasetime '12h'
>      option instance 'main'  <-------- We specify the instance to be 
> used for the lan interface.
> 
> You will now have two instances of dnsmasq running, in our example, one 
> is using opendns, and the other using the default (isp provided) dns 
> servers. When we specified instance 'main', we let all devices joining 
> our network use opendns servers.
> 
> 
> 2. Create a firewall rule to add exceptions which will redirect to port 
> 5353, our "secondary" dnsmasq instance, like so /etc/config/firewall:
> 
> config redirect
>      option name 'DNS_exceptions'
>      option target 'DNAT'
>      option src 'lan'
>      option proto 'udp'
>      option src_dport '53'
>      option dest_ip '192.168.1.1' <--- your router's own IP.
>      option dest_port '5353' <----- port of secondary dnsmasq instance.
>      option dest 'lan'
>      list src_mac '33:22:11:CC:BB:AA'
>      list src_mac '44:44:55:CC:BB:AA'
> 
> Regards,
> A. Benz
> 


Thank you for the configuration example! It helped me very much.

After reading dhcp config documentation on OpenWrt website[1], I went 
with an easier solution:

(in /etc/config/dhcp)

config host
         option name 'MyPC'
         option dns '1'
         option mac 'XX:XX:XX:XX:XX:XX'
         option ip '192.168.xx.xx'
         option tag 'cloudflaredns'

config host
         option name 'MyOtherPC'
         option dns '1'
         option mac 'XX:XX:XX:XX:XX:XX'
         option ip '192.168.xx.xx'
         option tag 'googledns'

config tag 'cloudflaredns'
         list dhcp_option '6,1.1.1.1,1.0.0.1'
         option force '1'

config tag 'googledns'
         list dhcp_option '6,8.8.8.8,8.8.4.4'
         option force '1'

This way only this host gets alternate DNS server configuration from the 
DHCP server.

Thanks again for your help, and thank to all of you for a great firmware!

It woud be fantastic if some day I could configure tags in Luci and 
assign static host to those tags.

Cheers,
Mikael

[1] https://openwrt.org/docs/guide-user/base-system/dhcp_configuration

_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list