dnsrouteropenwrtuci

Changing DNS settings in openwrt uci command line


How can I change the DNS settings using the command line in an openwrt router? I see these files here here

/etc/config/ddns /etc/config/ipset-dns But I slo see dnsmasq installed

but not sure which can change the DNS servers on the router

My end goal is to add a cron job that adds a custom DNS for couple of hours per day, then revert to the original DNS

Edit: I've found the following commands, can anybody explain?

uci set network.wan.dns='<list of space-separated DNS server IPs>'

uci commit network

reload_config

and

uci set network.wan.peerdns='0'

uci del network.wan.dns

uci add_list network.wan.dns='9.9.9.9'

uci add_list network.wan.dns='149.112.112.112'

uci commit


Solution

  • You can forward DNS requests to specific servers by doing:

    uci add_list dhcp.@dnsmasq[0].server="SERVER_ADDRESS"

    uci commit dhcp

    service dnsmasq restart or /etc/init.d/dnsmasq restart

    You can read more about this here: https://openwrt.org/docs/guide-user/base-system/dhcp_configuration (scroll down or find 'DNS forwarding')