Configure the DNS server IP Address

Source: Internet
Author: User
1 ############################ script functions and instructions ###### ############# 2 # configure the DNS server IP address on the local server 3 # Creation Time: 4 5 ########################## define a function ########## ################## 6 # define a function: configure DNS 7 # onid as the nic id; $ dnsservers is the IP address list of the DNS server to be configured 8 function dnsconfig ($ connectionid, [array] $ dnsservers) 9 {10 # determine whether the current system is 2003 (5) or 2008. The commands used when setting the DNS server are different 11 if (gwmi win32_operatingsystem ). version. split (". ") [0]-EQ 5) 12 {13 netsh.exe interface IP Set DNS "$ connectionid" static $ dnsservers [0] primary14 $ dnsservers [1 .. $ dnsservers. count] | % {netsh.exe interface IP add DNS "$ connectionid" $ _} 15} 16 else 17 {18 netsh.exe interface IP Set dnsservers "$ connectionid" static $ dnsservers [0] primary validate = no19 $ dnsservers [1 .. $ dnsservers. count] | % {netsh.exe interface IP add dnsservers "$ connectionid" $ _ validate = No} 20} 21} 22 23 ################ script start ############### ######################################## ############## 24 $ Index = (gwmi win32_networkadapterconfiguration |? {$ _. Defaultipgateway-ne $ null }). index25 [array] $ IP = (gwmi win32_networkadapterconfiguration-filter "Index = $ Index "). ipaddress26 $ connectionid = (gwmi win32_networkadapter-filter "Index = $ Index "). netconnectionid 27 # Set dns28 $ ip2 = $ IP [0] According to the IP address that belongs to the IDC. split ("\. ") [0, 1]-join ". "29 if ($ ip2-EQ" 10.4 ") 30 {31 $ dnsservers =" 10.4.2.220 "," 10.5.2.220 ", "192.168.251.210" 32 dnsconfig $ connectionid $ dnsservers33} 34 elseif ($ ip2-EQ "10.5") 35 {36 $ dnsservers = "10.5.2.220", "192.168.251.210 ", "10.4.2.220" 37 dnsconfig $ connectionid $ dnsservers38} 39 else 40 {41 $ dnsservers = "192.168.251.210", "10.4.2.220 ", "10.5.2.220" 42 dnsconfig $ connectionid $ dnsservers43} 44 45 # view local DNS Server LIST 46 $ DNSS = gwmi win32_networkadapter-filter "netconnectionstatus = 2" | foreach {(gwmi win32_networkadapterconfiguration-filter" index = $ ($ _. index )"). dnsserversearchorder} 47 $ DNSS

 

Configure the DNS server IP Address

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.