从命令行更改 OpenWrt 路由器中的 DNS 服务器

从命令行更改 OpenWrt 路由器中的 DNS 服务器

如何使用 OpenWrt 路由器中的命令行更改 DNS 设置?我看到这些文件位于“UCI 系统”文档

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

但我还看到安装了 dnsmasq

但不确定哪个可以更改路由器上的 DNS 服务器

我的最终目标是添加一个 cron 作业,每天添加几个小时的自定义 DNS 服务器,然后恢复到原始 DNS。

我发现了以下命令;有人可以解释一下吗?

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

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

答案1

OpenWRT 文档提供了此配置的示例,请参阅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

相关内容