首页 文章

以编程方式在Windows TCP / IP中更改NameServer

提问于
浏览
2

我正在构建一个VPN应用程序,我需要以编程方式设置DNS服务器 . 我正在更改注册表中的 NameServer 参数(在 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces 中)以将名称服务器添加到现有条目列表中 . 一旦我这样做,如果我尝试使用 nslookup 查找主机名,它工作正常,但 ping 无法解析名称 - 持续15分钟 . 并且15分钟后ping也能够解析名称 . 我've tried my own little TCP/IP app, and that has the same issue. I looked at the traffic in wireshark, and I see that nslookup is sending dns lookup requests, while ping isn' t .

无论如何,我可以踢窗户以提前通知名称服务器吗?或者有更好的方法在Windows中设置名称服务器?

在此先感谢您的帮助!

1 回答

  • 4

    不要直接更改该注册表项 . 如您所见,它不会通知DNS客户端名称服务器已更改 .

    最简单的解决方案可能是 %SystemRoot%\system32\netsh.exe .

    netsh interface ip set dns name="Local Area Connection" source=static addr=...
    

相关问题