Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm using OpenVPN on a Linux box and I need a method to push this setting to client, in order to be able reach machine.example.com within *.example.com.I've tried to use openvpn's config to do this, and seem that if the client is using Windows isn't working.

In order to solve this, I need a bat file to change dns search path on windows client machine after vpn connection establishment.

share|improve this question
add comment

2 Answers

wmic nicconfig where "description='NAME OF THE ADAPTER HERE'" call setdnsserversearchorder("", "")

To see all the fun other stuff you can do with this class (Win32_NetworkAdapterConfiguration), see here or check out the method docs.

wmic nicconfig call /?

EDIT: As I pointed out later, you probably want one of these instead:

wmic nicconfig where "description='NAME OF THE ADAPTER HERE'" call setdnsdomain("yourdomain.tld") (so yourdomain.tld is like "microsoft.com" in the official documentation).


If you want to change the order of domains you search (if you have a bunch, you try setdnssuffixsearchorder().

wmic nicconfig where "description='NAME OF THE ADAPTER HERE'" call setdnssuffixsearchorder("yourdomain1.tld", "yourdomain2.tld")

If you want to apply this to every card or adapter, you can just say anyone that is not null. I have not tested this and do not know the impact on the OS and VPN-based virtual adapters on your system, so please test that before destroying a production box). So, revisit the above example.

wmic nicconfig where "description=!=null" call setdnssuffixsearchorder("yourdomain1.tld", "yourdomain2.tld")

Again, look at the caveat above. So, if you want this in a quick and dirty batch file, just do something like this (for a specific adapter at this point, I want you to know if you need to apply to all before you copy one of my half-assed scripts. I madea pretty junky one for you on Pastebin. I hope it helps. I have dumped it to the screen below. Make sure to "quote your adapter name" and quote "your domain name" when using the batch file, or it will be most unfun with the crazy results that will bork your computer.



ECHO You did not mention an adapter for me to configure.
ECHO Goodbye!


REM Make sure that other than setting the adapter name,
REM you actually have a domain set.


ECHO You did not supply a domain you want configured.
ECHO Goodbye!


%WINDIR%\system32\wmic.exe nicconifg "where description='%~1'" call setdnsdomain("%~2")


ECHO Uh-oh. WMIC seems to have not exited gracefully.
ECHO The error code was %ERRORLEVEL%.
ECHO Goodbye!

share|improve this answer
Sorry I was lazy and forgot the original post, but holler back if you are not sure how to include this into a batch script. –  ajstein Jan 19 '11 at 14:53
And like an idiot, I think what you really need is setdnsdomain() or setdnssuffixsearchorder(). –  ajstein Jan 19 '11 at 14:56
I'm getting ERROR: Code = 0x80041017 Description = Invalid query Facility = WMI when I try your example in a single line test.bat file.(I'm not a windows sysadmin and I'm a bit confused ) –  silviu.h Jan 20 '11 at 10:32
I amended my answer to make it clearer. I hope some more advanced people can point you in the right direction if I am way off. –  ajstein Jan 20 '11 at 14:56
add comment

I think you can do that using wmic, but I'm not sure how.

Every version of Windows also has an option called something like Append primary and connection specific DNS suffixes that might help.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.