Set DNS server for OpenWrt itself

I want to set a DNS server for OpenWRT itself manually, so according to the official docs about DNS and DHCP configuration /etc/config/dhcp I added the server to the dnsmasq section as follows (see the last line of it):

config dnsmasq
        option domainneeded '1'
        option boguspriv '1'
        option filterwin2k '0'
        option localise_queries '1'
        option rebind_protection '1'
        option rebind_localhost '1'
        option local '/lan/'
        option domain 'lan'
        option expandhosts '1'
        option nonegcache '0'
        option authoritative '1'
        option readethers '1'
        option leasefile '/tmp/dhcp.leases'
        option nonwildcard '1'
        option localservice '1'
        option resolvfile '/tmp/resolv.conf.d/resolv.conf.auto'
        option server '8.8.8.8' # <====================== added this line

However, after reboot, it's still not in /etc/resolv.conf and DNS lookup doesn't work (it does when manually adding the 8.8.8.8 to /etc/resolv.conf, however this is only temporary) . So, what's the correct way to set the DNS server for the OpenWRT system itself?

What you did was passing google to your clients (and you only have part of it). Its fully detailed here
https://openwrt.org/docs/guide-user/base-system/dhcp_configuration#providing_custom_dns_with_dhcp that provides clients with custom DNS.

What you are wanting is to set DNS for your router itself. That lives in the/etc/config/network file.
Its detailed here : https://openwrt.org/docs/guide-user/base-system/dhcp_configuration#upstream_dns_provider

But I put examples and script below.

config interface 'wan'
	option device 'eth0'
	option proto 'dhcp'
	list dns '1.1.1.1'
	list dns '1.0.0.1'
	option peerdns '0'

config interface 'wan6'
	option device 'eth0'
	option proto 'dhcpv6'
	list dns '2606:4700:4700::1111'
	list dns '2606:4700:4700::1001'
	option peerdns '0'

This sets up your router to use Cloudflare's DNS. Change as required.

# Configure DNS provider
uci -q delete network.wan.dns
uci add_list network.wan.dns="1.1.1.1"
uci add_list network.wan.dns="1.0.0.1"
 
# Configure IPv6 DNS provider
uci -q delete network.wan6.dns
uci add_list network.wan6.dns="2606:4700:4700::1111"
uci add_list network.wan6.dns="2606:4700:4700::1001"
 
# Disable peer ISP DNS
uci set network.wan.peerdns="0"
uci set network.wan6.peerdns="0"

# Save changes
uci commit network

# Restart network  service to reflect changes
/etc/init.d/network restart
1 Like

thank you for your detailed reply, that just worked :slight_smile:

1 Like

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