以编程方式更改 Windows TCP/IP 中的名称服务器

发布于 2024-08-09 12:54:19 字数 435 浏览 1 评论 0原文

我正在构建一个 VPN 应用程序,需要以编程方式设置 DNS 服务器。我正在更改注册表中的 NameServer 参数(在 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces 中),以将名称服务器添加到现有条目列表中。执行此操作后,如果我尝试使用 nslookup 查找主机名,它工作正常,但 ping 无法解析该名称 - 15 分钟。 15 分钟后 ping 也能解析该名称。我尝试过我自己的 TCP/IP 小应用程序,它也有同样的问题。我查看了wireshark中的流量,发现nslookup正在发送dns查找请求,而ping则没有。

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

预先感谢您的帮助!

I am building a VPN application where I need to set DNS server programmatically. I am changing NameServer parameter in the registry (in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces) to prepend a name server to the list of existing entries. Once I do this, if I try to look up a host name using nslookup, it works fine, but ping is not able to resolve the name - for 15 minutes. And after 15 mins ping is also able to resolve the name. I'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.

Is there anyway I can kick windows to notice the name server earlier? Or is there a better way to set name servers in windows?

Thanks in advance for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稍尽春風 2024-08-16 12:54:19

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

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

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

Don't change that registry key directly. As you've found, it doesn't notify DNS clients that the nameserver has changed.

The easiest solution is probably %SystemRoot%\system32\netsh.exe.

netsh interface ip set dns name="Local Area Connection" source=static addr=...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文