원문 : http://www.ischo.net -- 조인상 //시스템 엔지니어

+++++++++++++++++++++++++++++++++++++++++++++++++++++++



netsh command 를 이용한 DNS서버 변경하기


조건 : Windows 7 PC에 cable이 연결된 활성 NIC에만 DNS서버 변경



아래 스크립트 작성후 관리자 권한으로 실행.



@echo off

rem ###########################################
rem # Shell script : DNS서버 변경 프로그램    #
rem # script by ischo.                        #
rem # * 활성 NIC에 DNS서버 변경               #
rem ###########################################


rem ###########################################
rem # 환경설정                                #
rem # DNS서버를 이곳에 설정하세요             #
rem ###########################################
set DNS1=168.126.63.1
set DNS2=8.8.8.8


rem ###########################################
rem #               명령부                    #
rem ###########################################

chcp 949

cls

for /f "tokens=1,2,3*" %%i in ('netsh int show interface') do (
    if %%i equ 사용 (
 echo "########################################################"
        echo "#  Changing "%%l" : %DNS1% + %DNS2%
 echo "########################################################"

        netsh int ipv4 set dns name="%%l" static %DNS1% primary validate=no
        netsh int ipv4 add dns name="%%l" %DNS2% index=2 validate=no
 netsh int ip show dnsservers name="%%l"
    )
)

ipconfig /flushdns


:EOF




OR using wmic command


wmic nicconfig where (IPEnabled=TRUE) call SetDNSServerSearchOrder ("8.8.8.8")

wmic nicconfig where (IPEnabled=TRUE) call SetDNSServerSearchOrder ("8.8.8.8", "8.8.4.4")

wmic nicconfig where "(IPEnabled=TRUE) and (Description = 'Local Area Connection')"  call SetDNSServerSearchOrder ("8.8.8.8", "8.8.4.4")




(*.118.235.233)