How to set properly DNS server on OpenWrt device?

If wan interface goes down it won't be used.

Package installation or upgrade. It doesn't hurt.

1 Like

Package installation and NTP time synchronization.

1 Like

Okay, I got it. Thanks for your examples and have a nice day.

2 Likes

What's the difference between that setting (which I think is what https://openwrt.org/docs/guide-user/base-system/dhcp_configuration#upstream_dns_provider describes) and
Network -> DHCP and DNS -> DNS forwardings (I did it via uci following https://openwrt.org/docs/guide-user/base-system/dhcp_configuration#dns_forwarding)?

Setting DNS server in LAN or WAN on Custom DNS will add the DNS servers to:
resolv.conf.auto
This file is queried by DNSMasq for the upstream resolvers to use.

This file can easily be manipulated from outside to add/remove the DNS servers (e.g. when using VPN), DNSMasq will monitor this file and reread on change.

This file is not read if the no-resolv directive is set in DNSMasq.

Now enter the Network -> DHCP and DNS -> DNS forwardings this will add the upstream resolvers in the dnsmasq.conf file as server=x.x.x.x and is always read.

In normal use there probably is not much difference and DNSmasq will query resolv.conf.auto and use the server=x.x.x.x as upstream resolvers.

At least that is my understanding but I am not an experienced OpenWRT users.

1 Like

Thanks!
The thing that confused me is that I didn't see the DNS servers I specified in resolv.conf.auto, but after a grep -r <IP-address-of-dns-server>, I found it in /tmp/etc/dnsmasq.conf.cfg01411c, which I guess is read in somewhere.

The IP addresses I added are OpenNIC servers and I may/might create a script sometime which pings a whole bunch and then enables/prioritizes the ones online and fastest, so having them in resolv.conf.auto seems the better place.

What I did find in resolv.conf.auto was the address of the advertised by peer, which I explicitly didn't want as that would mean my ISP's DNS servers (when deployed as my main router).

Agreed :slight_smile:

That is one reason to add your upstream DNS servers in the WAN as that is the place where you can disable advertised by peer (I also always disable that as I do not want my ISP DNS server)

1 Like