views:

195

answers:

1

Hello, 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!

+2  A: 

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=...
ephemient
Thank you. Does static in this command apply only for static interfaces or can you use this for DHCP based interfaces as well? Ideally would like to be able to add the name server to the list of servers provided by DHCP server. I've looked at the netsh documentation but it's a little bit vague on this. Thank you once again.