Change DNS servers in an OpenWrt router from command line

7,513

The OpenWRT documentation provides an example of this configuration, see https://openwrt.org/docs/guide-user/base-system/dhcp_configuration

# Configure DNS provider
uci set network.wan.peerdns="0"
uci set network.wan.dns="8.8.8.8 8.8.4.4"
uci set network.wan6.peerdns="0"
uci set network.wan6.dns="2001:4860:4860::8888 2001:4860:4860::8844"
uci commit network
service network reload
Share:
7,513

Related videos on Youtube

Tlink
Author by

Tlink

Updated on September 18, 2022

Comments

  • Tlink
    Tlink over 1 year

    How can I change the DNS settings using the command line in an OpenWrt router? I see these files in the documentation of "The UCI system":

    • /etc/config/ddns
    • /etc/config/ipset-dns

    But I also 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 server for couple of hours per day, then revert to the original DNS.

    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