Specify which DNS servers to use to resolve hostnames in .NET

.net, c#, dns, networking

Solution

No this cannot be done with the .Net Framework. The Dns.Resolve method relies on the internal Win32 APIs which in turn go through the DNS servers associated with the network connection.

In order to get this to work, you'd have to change the DNS servers associated with the network adapter's address.

Problem

I'd like to know if there's any way to force the System.Net.Dns class to resolve hostnames using a set of custom DNS servers instead of using the ones that are associated with the main network connection. I suspect that this is only possible using a custom library like DnDns (http://dndns.codeplex.com), but I was hoping this could be done from within .NET.

Original source