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.
If you're able to run your application inside a docker container you can provide the dns server ip address on start up.
docker run --dns=1.2.3.4 repo/myimage command.exe
https://docs.docker.com/v17.09/engine/userguide/networking/configure-dns/
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.
Tested in .net standard:
You can do this with "JH Software's DNS Client for .NET" - without changing the DNS local servers. See the second code sample at http://www.simpledns.com/dns-client-lib.aspx