Skip to content

Windows搭建CoreDNS解析

CoreDNS 服务器配置

配置这个需要配合wireguard等vpn软件,连接后将dns指向公网服务器的虚拟ip

这样再连接就不用走cloudflared 的穿透了

CoreDNS GitHub 下载

在同一个目录下新建一个文本文件,命名为 Corefile(注意:没有后缀名),内容如下:

reinffy.cc {
    # 匹配 reinffy.cc 及其所有子域名
    hosts {
        10.0.0.1 reinffy.cc
        10.0.0.1 openlist.reinffy.cc
        # 只要你在这个 hosts 块里列出的,都会优先返回内网 IP
        fallthrough
    }
    # 如果 hosts 块里没写,也可以用这个万能转发,转发给公共 DNS
    forward . 114.114.114.114 223.5.5.5
    log
}

# 其他所有域名的解析(如百度、谷歌)
. {
    forward . 114.114.114.114 223.5.5.5
    log
}

客户端测试 nslookup reinffy.cc

直接指向服务器即可

一键启动脚本

右键管理员启动

启动时确保文件在同一目录下

  • coredns.exe
  • Corefile
bat
@echo off
setlocal enabledelayedexpansion

:: 1. Move to the directory where the script is located
pushd "%~dp0"

echo [STEP 1/3] Disabling ICS Service (SharedAccess)...
sc stop SharedAccess >nul 2>&1
sc config SharedAccess start= disabled >nul 2>&1

echo [STEP 2/3] Cleaning up port 53...
:: Find PID using port 53 and kill it
for /f "tokens=5" %%i in ('netstat -ano ^| findstr :53 ^| findstr LISTENING') do (
    echo Found process %%i on port 53. Killing it...
    taskkill /f /pid %%i >nul 2>&1
)

echo [STEP 3/3] Starting CoreDNS...
echo ----------------------------------------
if not exist "Corefile" (
    echo ERROR: Corefile not found in this directory!
    pause
    exit
)

:: Run CoreDNS with the config file
coredns.exe -conf ./Corefile

pause