dnsmasq dns上游列表替换工具
Find a file
2025-02-14 13:08:23 +08:00
test-conf feat: 增加对 conf-dir 不止一个项的检查测试 和 conf-dir 存储的值不是目录的检查测试 2025-02-13 15:40:18 +08:00
dnsmasq-upstream-auto-replace.sh update: 修复文件名称 2025-02-14 12:44:25 +08:00
LICENSE Initial commit 2025-02-12 12:56:30 +00:00
makefile feat: 修改测试目录,不污染用户目录 2025-02-14 12:54:23 +08:00
README.md update: 润色第一个use case部分的文本 2025-02-14 13:08:23 +08:00

dnsmasq-upstream-auto-replace

dnsmasq dns上游列表替换工具

Documentation

Usage: ./dnsmasq-upstream-auto-replace.sh [OPTIONS]

Options:
  --conf, -c <file>       Specify the path to the dnsmasq configuration file (default: /etc/dnsmasq.conf)
  --debug, -d <level>     Set the debug level (options: info, success, warn, error)
  --map, -m <map>         Set the replace map (example: 1.1.1.1-2.2.2.2,2.2.2.2-3.3.3.3)
  --list, -l              List all files in the conf dir
  --help, -h              Show this help message and exit

Debug Levels:
  info: Information messages
  success: Successful operations
  warn: Warning messages
  error: Error messages

Description:
This script checks the dnsmasq configuration file for a specific setting and replace upstream dns.

Use case

列出 conf-dir 键所指向目录中的文件

命令:

./dnsmasq-upstream-auto-replace.sh -l

返回:

[Success] Target folder has been found.
[info] All files in the conf dir:
[file] /etc/dnsmasq.d/accelerated-domains.china.114.114.114.114.conf
[file] /etc/dnsmasq.d/accelerated-domains.china.114.114.115.115.conf
[file] /etc/dnsmasq.d/accelerated-domains.china.119.29.29.29.conf
[file] /etc/dnsmasq.d/accelerated-domains.china.223.5.5.5.conf
[file] /etc/dnsmasq.d/apple.china.114.114.114.114.conf
[file] /etc/dnsmasq.d/apple.china.114.114.115.115.conf
[file] /etc/dnsmasq.d/apple.china.119.29.29.29.conf
[file] /etc/dnsmasq.d/apple.china.223.5.5.5.conf
[file] /etc/dnsmasq.d/bogus-nxdomain.china.conf
[file] /etc/dnsmasq.d/google.china.114.114.114.114.conf
[file] /etc/dnsmasq.d/google.china.114.114.115.115.conf
[file] /etc/dnsmasq.d/google.china.119.29.29.29.conf
[file] /etc/dnsmasq.d/google.china.223.5.5.5.conf

替换上游 dns

命令:

./dnsmasq-upstream-auto-replace.sh -c /etc/dnsmasq.conf -m 114.114.114.114-221.6.4.66,119.29.29.29-221.6.4.66,223.5.5.5-221.6.4.66,114.114.115.115-221.6.4.66

tips:
-c 并不必要多数发行版中dnsmasq配置文件的位置是 /etc/dnsmasq.conf,本脚本已经将此作为默认值。

返回:

[Success] Target folder has been found.
[replace rule] 114.114.114.114 -> 221.6.4.66
[replaced] /etc/dnsmasq.d/accelerated-domains.china.114.114.114.114.conf
[replaced] /etc/dnsmasq.d/accelerated-domains.china.114.114.115.115.conf
[replaced] /etc/dnsmasq.d/accelerated-domains.china.119.29.29.29.conf
[replaced] /etc/dnsmasq.d/accelerated-domains.china.223.5.5.5.conf
[replaced] /etc/dnsmasq.d/apple.china.114.114.114.114.conf
[replaced] /etc/dnsmasq.d/apple.china.114.114.115.115.conf
[replaced] /etc/dnsmasq.d/apple.china.119.29.29.29.conf
[replaced] /etc/dnsmasq.d/apple.china.223.5.5.5.conf
[replaced] /etc/dnsmasq.d/bogus-nxdomain.china.conf
[replaced] /etc/dnsmasq.d/google.china.114.114.114.114.conf
[replaced] /etc/dnsmasq.d/google.china.114.114.115.115.conf
[replaced] /etc/dnsmasq.d/google.china.119.29.29.29.conf
[replaced] /etc/dnsmasq.d/google.china.223.5.5.5.conf
[replace rule] 119.29.29.29 -> 221.6.4.66
[replaced] /etc/dnsmasq.d/accelerated-domains.china.114.114.114.114.conf
[replaced] /etc/dnsmasq.d/accelerated-domains.china.114.114.115.115.conf
[replaced] /etc/dnsmasq.d/accelerated-domains.china.119.29.29.29.conf
[replaced] /etc/dnsmasq.d/accelerated-domains.china.223.5.5.5.conf
[replaced] /etc/dnsmasq.d/apple.china.114.114.114.114.conf
[replaced] /etc/dnsmasq.d/apple.china.114.114.115.115.conf
[replaced] /etc/dnsmasq.d/apple.china.119.29.29.29.conf
[replaced] /etc/dnsmasq.d/apple.china.223.5.5.5.conf
[replaced] /etc/dnsmasq.d/bogus-nxdomain.china.conf
[replaced] /etc/dnsmasq.d/google.china.114.114.114.114.conf
[replaced] /etc/dnsmasq.d/google.china.114.114.115.115.conf
[replaced] /etc/dnsmasq.d/google.china.119.29.29.29.conf
[replaced] /etc/dnsmasq.d/google.china.223.5.5.5.conf
[replace rule] 223.5.5.5 -> 221.6.4.66
[replaced] /etc/dnsmasq.d/accelerated-domains.china.114.114.114.114.conf
[replaced] /etc/dnsmasq.d/accelerated-domains.china.114.114.115.115.conf
[replaced] /etc/dnsmasq.d/accelerated-domains.china.119.29.29.29.conf
[replaced] /etc/dnsmasq.d/accelerated-domains.china.223.5.5.5.conf
[replaced] /etc/dnsmasq.d/apple.china.114.114.114.114.conf
[replaced] /etc/dnsmasq.d/apple.china.114.114.115.115.conf
[replaced] /etc/dnsmasq.d/apple.china.119.29.29.29.conf
[replaced] /etc/dnsmasq.d/apple.china.223.5.5.5.conf
[replaced] /etc/dnsmasq.d/bogus-nxdomain.china.conf
[replaced] /etc/dnsmasq.d/google.china.114.114.114.114.conf
[replaced] /etc/dnsmasq.d/google.china.114.114.115.115.conf
[replaced] /etc/dnsmasq.d/google.china.119.29.29.29.conf
[replaced] /etc/dnsmasq.d/google.china.223.5.5.5.conf
[replace rule] 114.114.115.115 -> 221.6.4.66
[replaced] /etc/dnsmasq.d/accelerated-domains.china.114.114.114.114.conf
[replaced] /etc/dnsmasq.d/accelerated-domains.china.114.114.115.115.conf
[replaced] /etc/dnsmasq.d/accelerated-domains.china.119.29.29.29.conf
[replaced] /etc/dnsmasq.d/accelerated-domains.china.223.5.5.5.conf
[replaced] /etc/dnsmasq.d/apple.china.114.114.114.114.conf
[replaced] /etc/dnsmasq.d/apple.china.114.114.115.115.conf
[replaced] /etc/dnsmasq.d/apple.china.119.29.29.29.conf
[replaced] /etc/dnsmasq.d/apple.china.223.5.5.5.conf
[replaced] /etc/dnsmasq.d/bogus-nxdomain.china.conf
[replaced] /etc/dnsmasq.d/google.china.114.114.114.114.conf
[replaced] /etc/dnsmasq.d/google.china.114.114.115.115.conf
[replaced] /etc/dnsmasq.d/google.china.119.29.29.29.conf
[replaced] /etc/dnsmasq.d/google.china.223.5.5.5.conf
[Success] Applied all replace rules

替换上游 dns | 修改提示等级

命令:

./dnsmasq-upstream-auto-replace.sh -d success -c /etc/dnsmasq.conf -m 114.114.114.114-221.6.4.66,119.29.29.29-221.6.4.66,223.5.5.5-221.6.4.66,114.114.115.115-221.6.4.66

返回:

[Success] Target folder has been found.
[Success] Applied all replace rules