{"id":21056102,"url":"https://github.com/217heidai/nestingdns","last_synced_at":"2025-04-06T00:06:59.497Z","repository":{"id":216280977,"uuid":"740753425","full_name":"217heidai/NestingDNS","owner":"217heidai","description":"AdGuardHome、MosDNS、SmartDNS 套娃使用实践","archived":false,"fork":false,"pushed_at":"2024-12-19T02:59:21.000Z","size":825,"stargazers_count":112,"open_issues_count":2,"forks_count":29,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-29T23:07:33.192Z","etag":null,"topics":["adguardhome","docker","mosdns","smartdns"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/217heidai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-09T01:52:04.000Z","updated_at":"2025-03-29T12:39:00.000Z","dependencies_parsed_at":"2024-01-30T08:28:45.576Z","dependency_job_id":"d8e96974-4aa4-4f10-836b-f73a906577be","html_url":"https://github.com/217heidai/NestingDNS","commit_stats":null,"previous_names":["217heidai/nestingdns"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/217heidai%2FNestingDNS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/217heidai%2FNestingDNS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/217heidai%2FNestingDNS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/217heidai%2FNestingDNS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/217heidai","download_url":"https://codeload.github.com/217heidai/NestingDNS/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247415967,"owners_count":20935388,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adguardhome","docker","mosdns","smartdns"],"created_at":"2024-11-19T16:48:54.300Z","updated_at":"2025-04-06T00:06:59.480Z","avatar_url":"https://github.com/217heidai.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NestingDNS\nDNS 三大神器 [AdGuardHome](https://github.com/AdguardTeam/AdGuardHome)、[MosDNS](https://github.com/IrineSistiana/mosdns)、[SmartDNS](https://github.com/pymumu/smartdns)，该如何选择？  \n不，小孩子才做选择，我全都要。  \n于是有了这个项目，套娃使用三大神器，试图找到一套最佳实践。\n\n# DNS 解析流程\n1. AdGuardHome 为第一层 DNS ，作为整体入口，监听端口 4053。\n- 负责去广告。\n2. MosDNS 为第二层 DNS，监听端口 5053。\n- 负责分流。\n    - 直连：待解析域名在 [direct-list.txt](https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/direct-list.txt)、[apple-cn.txt](https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/apple-cn.txt)、[google-cn.txt](https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/google-cn.txt)、force-cn.txt(自定义不走代理的域名)内，通过 SmartDNS 的 mainland 组进行解析。\n    - 代理：待解析域名在 [proxy-list.txt](https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/proxy-list.txt)、[gfw.txt](https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/gfw.txt)、[greatfire.txt](https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/greatfire.txt)、force-nocn.txt(自定义走代理的域名)内，通过 SmartDNS 的 gfw 组进行解析。\n    - Fallback：待解析域名不在以上规则内的，先使用 SmartDNS 的 mainland 组进行解析，如解析出来的地址为国内 IP(在 [CN-ip-cidr.txt](https://raw.githubusercontent.com/Hackl0us/GeoIP2-CN/release/CN-ip-cidr.txt) 内)则使用，否则抛弃。再使用 SmartDNS 的 gfw 组进行解析，如解析成功则使用，如失败则使用 SmartDNS 的 overseas 组进行解析（gfw 组使用代理连接公共 DNS，当代理异常时使用 overseas 组作为备用进行解析）。\n3. SmartDNS 为第三层 DNS，监听端口 6053、7053、8053\n- 负责 DNS 解析、测速、缓存。\n    - mainland 组，端口 7053，通过 DoT 接入上游 AliDNS、DNSPod、360DNS，负责直连域名解析。\n    - gfw 组，端口 8053，通过代理使用 DoH 接入上游 Google、Cloudflare、Quad9，负责代理域名解析，关闭缓存、测速。\n    - overseas 组，端口 6053，通过 DoT 接入上游 Google、Cloudflare、Quad9、Quad101、DNS.SB、NextDNS，作为备用域名解析，关闭缓存、测速。\n\n![NestingDNS](docs/NestingDNS.png)\n\n# 安装方法\n使用 Docker 一键安装。  \n1. network host 模式（推荐使用）\n```bash\ndocker run -d \\\n    --restart unless-stopped \\\n    --name nestingdns \\\n    --network host \\\n    -v $HOME/nestingdns/etc:/nestingdns/etc \\    # 配置文件路径\n    -v $HOME/nestingdns/work:/nestingdns/work \\  # 工作文件路径\n    -v $HOME/nestingdns/log:/nestingdns/log \\    # 日志文件路径\n    -e TZ=Asia/Shanghai \\\n    -e SCHEDULE=\"0  4  *  *  *\" \\  # 每天 4 点更新规则文件，重启 MosDNS\n    217heidai/nestingdns\n```\n\n2. 端口映射模式（MosDNS、SmartDNS 的端口可以不映射）\n```bash\ndocker run -d \\\n    --restart unless-stopped \\\n    --name nestingdns \\\n    -p 3000:3000 \\      # AdGuardHome web 页面\n    -p 4053:4053 \\      # AdGuardHome NDS\n    -p 4053:4053/udp \\  # AdGuardHome NDS\n    -p 5053:5053 \\      # MosDNS NDS\n    -p 5053:5053/udp \\  # MosDNS NDS\n    -p 6053:6053 \\      # SmartDNS NDS\n    -p 6053:6053/udp \\  # SmartDNS NDS\n    -p 7053:7053 \\      # SmartDNS NDS\n    -p 7053:7053/udp \\  # SmartDNS NDS\n    -p 8053:8053 \\      # SmartDNS NDS\n    -p 8053:8053/udp \\  # SmartDNS NDS\n    -v $HOME/nestingdns/etc:/nestingdns/etc \\    # 配置文件路径\n    -v $HOME/nestingdns/work:/nestingdns/work \\  # 工作文件路径\n    -v $HOME/nestingdns/log:/nestingdns/log \\    # 日志文件路径\n    -e TZ=Asia/Shanghai \\\n    -e SCHEDULE=\"0  4  *  *  *\" \\  # 每天 4 点更新配置文件，重启 MosDNS\n    217heidai/nestingdns\n```\n\n# 配置说明\n***默认已全部关闭 IPv6 支持。***\n## AdGuardHome\nAdGuardHome 配置文件为 `$HOME/nestingdns/etc/conf/adguardhome.yaml`。\n- ***默认已配置好，一般无需调整***。\n- 可通过 3000 端口的 web 进行配置，默认账号 root 密码 password。\n- 默认开启缓存，并关闭乐观缓存，AdGuardHome 仅作临时缓存。主要缓存功能由 SmartDNS 负责。\n- 默认内置去广告规则 [AdBlock DNS Filters](https://github.com/217heidai/adblockfilters)。\n\n## MosDNS\nMosDNS 配置文件为 `$HOME/nestingdns/etc/conf/mosdns.yaml`、`$HOME/nestingdns/etc/conf/mosdns_load_rules.yaml`、`$HOME/nestingdns/etc/conf/mosdns_forward.yaml`。\n- ***默认已配置好，一般无需调整***。各项配置可参考官方 [wiki](https://irine-sistiana.gitbook.io/mosdns-wiki/)。\n- 分流规则文件路径为 `$HOME/nestingdns/etc/site/`。根据创建容器时的 SCHEDULE 参数，定时下载更新分流规则文件，默认每天 4 点更新。\n- 自定义不走代理规则文件为 `$HOME/nestingdns/etc/site/force-cn.txt`。默认为空，可自行添加内容，如填入 VPS 的域名。\n- 自定义走代理规则文件为 `$HOME/nestingdns/etc/site/force-nocn.txt`。默认为空，可自行添加内容。\n- 自定义 hosts 文件为 `$HOME/nestingdns/etc/site/hosts.txt`。默认为空，可自行添加内容（注意格式与操作系统的 hosts 不一样，具体请参考官方 [wiki](https://irine-sistiana.gitbook.io/mosdns-wiki/)）。\n- gfw TTL 默认全部调整为 300s，`$HOME/nestingdns/etc/conf/mosdns_forward.yaml` 中设置 sequence dns_gfw，***如有多个代理地址切换使用的，请设置较小值，如 60***。（上游 smartdns gfw 组默认已关闭缓存、测速）\n- ECS (EDNS0 Client Subnet) ，默认关闭。如需启用，请在 `$HOME/nestingdns/etc/conf/mosdns_forward.yaml` 中找到 ecs_us，设置为 VPS 所在地 IP，并放开调用前的注释。\n- CDN IP 优选，默认关闭。如需启用，请在 `$HOME/nestingdns/etc/conf/mosdns_forward.yaml` 中找到所有 best_ip，删掉注释，并设置相应 black_hole ip（建议多填几个不同网段的 ip）。测速工具推荐使用 [CloudflareSpeedTest](https://github.com/XIU2/CloudflareSpeedTest)（注意测速必须关闭代理）。由于测速需关闭代理，因此未做成自动化脚本，请定期手工测速。\n    - cloudflare 优选，请将测速较快的 ip 填入 `$HOME/nestingdns/etc/conf/mosdns_forward.yaml` 中 sequence blackhole_cloudflare。\n\n## SmartDNS\nSmartDNS 配置文件为 `$HOME/nestingdns/etc/conf/smartdns.conf`。\n- **除代理外，其它默认已配置好，一般无需调整**。各项配置可参考官方 [wiki](https://pymumu.github.io/smartdns/)。\n- **使用科学上网的，请为 gfw 组配置通过代理进行 DNS 解析**，配置方式参见官方 [wiki proxy 部分](https://pymumu.github.io/smartdns/config/proxy/)。不使用科学上网的，无需配置。\n\n# 测试方法\n```\ndig @ip -p 4053 www.baidu.com\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F217heidai%2Fnestingdns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F217heidai%2Fnestingdns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F217heidai%2Fnestingdns/lists"}