Send DNS in DHCP petition

Hello!

I have DHCP enabled in my network with static lease for my known devices (laptop, server, phone, etc..) so I don't need to configure static ips in each of them.I have just installed a dockerized pihole in my network (IP 192.168.0.21) so I want this to be the first DNS option for each device connected.

So when a new lease is solicited, the router send not only the IP but the DNS servers (first my pihole, then google dns for example just in case my server is down). The problem now is the router is sending 192.168.0.1 (itself) as DNS server and then he resend the petition to the pihole.

Could this be changed?

I have:
DNS forwardings set in DHCP server settings (192.168.0.21, 8.8.8.8, 8.8.4.4)
Network > interfaces > wan > edit > Use custom DNS server (192.168.0.21, 8.8.8.8, 8.8.4.4)

But the 'problem' is still there. Is there anything I could do?
P.D: my ISP router is on the top of this 'architecture' with a DMZ to my openwrt.

1 Like

Disable peer DNS, remove Google DNS and use Pi-hole DNS exclusively, otherwise the final result is not reliable.

1 Like

The problem is that I need a backup DNS server (maybe in the openwrt itself) just in case my server goes down. Can this be achieved without using thirdparty DNS and without setting up another machine with pihole?

Thanks in advance!

Try this way:

uci -q delete network.lan.dns
uci add_list network.lan.dns="192.168.0.21"
uci commit network
/etc/init.d/network restart

uci -q delete dhcp.lan.dhcp_option
uci -q delete dhcp.lan.dns
uci -q delete dhcp.@dnsmasq[0].server
uci set dhcp.@dnsmasq[0].strictorder="1"
uci commit dhcp
/etc/init.d/dnsmasq restart
/etc/init.d/odhcpd restart
1 Like

Before trying that:

I just turned off my server (after checking that my computer appears in the pihole client list and it was working) and names are being resolved anyway. If I do a 'config /all' I can see my Pihole Ip as the only DNS server. How is my computer resolving then?

Sorry for so many questions and thanks for you help

Ok, I see in your code that what you are doing is setting my Pihole at first in the order but there are another DNS somewhere, right?

It should be like this:

  • Primary DNS - Dnsmasq @ OpenWrt - the only one visible in the client network configs
  • Secondary DNS - Pi-hole
  • Secondary DNS failover - peer DNS

Or you can add Google DNS instead of peer DNS on the WAN/LAN interface after Pi-hole:
https://openwrt.org/docs/guide-user/base-system/dhcp_configuration#upstream_dns_provider

1 Like

I think the OP wants to use option 6 in dhcp.
https://openwrt.org/docs/guide-user/base-system/dhcp_configuration#dhcp_options

2 Likes

The OP wants to use failover DNS when Pi-hole is down, however passing multiple DNS with DHCP makes it depend on the client implementation, which is not guaranteed to utilize strict order.

True, but in this case I would send the Pihole and the OpenWrt. If everything works fine, the hosts will query Pihole directly or OpenWrt, which in turn will query Pihole. If it is down, OpenWrt will try the nameservers of the wan.

This may result in a significant delay for the clients that don't remember DNS server status and use round robin or strict order methods for every DNS query.
In that case, 30-50% of the DNS queries would be answered only after Pi-hole DNS timeout.

1 Like

In fact, I just tried that and network is really slow. I'm still wondering how to do it because in you previous answer Dnsmasq @ OpenWrt is the first option and not Pihole.

Edit: Well, I found this. So I'm afraid I have to set up a raspberry pi as a backup!!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.