简体   繁体   English

如何在 .net 中为网络适配器设置 dns 搜索后缀?

[英]How do i set the dns search suffix for a network adapter in .net?

I've written a command line utility that detects which network interface is connected, and sets the staitc ip address and dns servers for it (by calling netsh).我编写了一个命令行实用程序,用于检测连接的网络接口,并为其设置 staitc ip 地址和 dns 服务器(通过调用 netsh)。 However, I can't seem to figure out how to set the dns search suffixes.但是,我似乎无法弄清楚如何设置 dns 搜索后缀。 netsh doesnt appear capable of doing that. netsh 似乎无法做到这一点。 How do I do that otherwise (WMI perhaps)?否则我该怎么做(也许是 WMI)?

I think you have to set the value(s) you want in the DNSDomainSuffixSearchOrder property of the Win32_NetworkAdapterConfiguration WMI object.我认为您必须在 Win32_NetworkAdapterConfiguration WMI 对象的 DNSDomainSuffixSearchOrder 属性中设置所需的值。

Here's and example of setting values in WMI, if you need it: Modifying Objects & Running Methods以下是在 WMI 中设置值的示例(如果需要): 修改对象和运行方法

The dns search suffixes are valid for the whole machine, not for a single network adapter. dns搜索后缀对整机有效,对单个网卡无效。 You can also get them from registry:您还可以从注册表中获取它们:

string searchList = "";
try 
{
    using (var reg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(tcpSettingsSubKey))
    {
        searchList = (reg.GetValue("SearchList") as string);
    }
}
catch(Exception ex)
{
    // something went wrong
}

(This is not the default dns suffix when the machine is an AD member) (这不是本机是AD会员时默认的dns后缀)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM