Append dns suffixes via windows command prompt

13

2

At my work, we have two connection specific DNS suffixes. lhs.local and cis.local. I'm trying to write a batch file that will take care of a lot of the common administrative tasks that need done when we deploy a computer, and appending these is one of those tasks.

Is there a command to do this programatically?

Chris Sobolewski

Posted 2010-10-11T13:40:16.137

Reputation: 613

1Why are you (ab?)using Zeroconf TLDs? – Ignacio Vazquez-Abrams – 2010-10-11T15:28:52.240

Please don't get me started, lol. Why am I the one who pioneered our imaging initiative when I'm just tier 2 support? – Chris Sobolewski – 2010-10-11T16:03:41.400

Answers

8

Via this post

In order to add a DNS suffix to a TCP/IP connection remotely, all you need is a list of IP addresses and the following command:

wmic /USER:administrator /PASSWORD:adminpassword /node:@c:\iplist.txt nicconfig call SetDNSSuffixSearchOrder (mydomain.com)

where C:\iplist.txt contains a list of IP addresses, line separated.

Another way is to add via the registry

reg add HKLM\System\currentcontrolset\services\tcpip\parameters /v “NV Domain” /d “mydomain.com” /f

There's a Microsoft KB entry for the same as well.

Sathyajith Bhat

Posted 2010-10-11T13:40:16.137

Reputation: 58 436

6Using the reg method above did not work for me. So I read the KB link which talks about setting the value name to "SearchList" not, e.g. "NV Domain". Using /v SearchList worked (note it will clobber any existing domains so be sure to have them in the /d list. – Nathan Kidd – 2013-01-25T17:26:07.297

2

Based off of Sathya's answer and other resources, I wrote this:

@echo off
SETLOCAL EnableDelayedExpansion

:: Input here the additional suffix
set suffix=your.own.suffix

:: Get existing DNS suffixes
FOR /F "usebackq tokens=1,2* delims= " %%A in (`reg QUERY HKLM\SYSTEM\CurrentControlSet\services\Tcpip\Parameters /V SearchList ^| findstr REG_SZ`) do ( 
    set OLD_DNS=%%C
)

:: Check if it starts with our suffix
set OK=NO
FOR /F "tokens=1,2* delims=," %%A in ("%OLD_DNS%") do (
    if "%%A" == "%suffix%" set OK=YES
)

:: Add our suffix first if it's not there
if "%OK%" == "NO" (
    echo Conf KO: %OLD_DNS%
    reg add HKLM\SYSTEM\CurrentControlSet\services\Tcpip\Parameters /V SearchList /D "%suffix%,%OLD_DNS%" /F
) else (
    echo Conf OK: %OLD_DNS%
)

ipconfig /flushdns

Benoit Duffez

Posted 2010-10-11T13:40:16.137

Reputation: 474