從命令列更改 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

相關內容