none
Changing static IP address and DNS to DHCP

Answers

All replies

  • What you are asking is not very clear.  Are you asking how to set the adapter to get DNS settings automatically?

    Have you looked into the repository.  There are many scripts that set DHCP and automatic updates for all items.

    http://gallery.technet.microsoft.com/scriptcenter/fe44e65d-7c73-46a3-93a6-ef2bf4344ca6

    Are you looking for this:

    http://msdn.microsoft.com/en-us/library/windows/desktop/aa393298(v=vs.85).aspx

    Here is a command that will clear the DNS settings if they are static.

    gwmi win32_networkadapterconfiguration -filter 'index=8'|
         ForEach-Object{
              $_.SetDNSServerSearchOrder()
         }


    ¯\_(ツ)_/¯

    Friday, May 18, 2012 8:25 PM
  • Xavior01, you may want to try this script.

    http://techibee.com/powershell/powershell-assign-static-ip-address/1053


    Thanks,

    Sitaram Pamarthi

    Blog : http://techibee.com

    Follow on Twitter

    This posting is provided AS IS with no warranties or gurentees,and confers no rights

    Saturday, May 19, 2012 5:33 PM
  • If I understood your question correctly you want enable the DHCP and setting maually the DNS.

    This is the command to set DHCP for the Local Area Connection adapter:
      netsh interface ipv4 set address name="Local Area Connection" source=dhcp

    and this is for set the dns on the adapters with DHCP enabled:
      wmic nicconfig where (IPEnabled=TRUE and DHCPEnabled=TRUE) call SetDNSServerSearchOrder(8.8.8.8, 192.168.1.1) 

    So you need a little script like this:
    @echo off
    netsh interface ipv4 set address name="Local Area Connection" source=dhcp
    wmic nicconfig where (IPEnabled=TRUE and DHCPEnabled=TRUE) call SetDNSServerSearchOrder(8.8.8.8, 192.168.1.1)

    This is the full script version with some control more than the three line before (and with the dns portion absent in old thread )

    echo off
    :: set-DhcpAndDns.cmd
    :: By Gastone Canali
    setlocal
    Rem *** check the operating system 
    (wmic os get caption |findstr "vista 7")1>nul 2>nul|| goto :NotVistaOr7
    
    Rem Get the index of the IPenabled adapters
    for /F %%I in ('wmic nicconfig where "IPEnabled=TRUE" get index ^|findstr /r [0-9]') do (
      Rem *** get the name of adapters with ip enabled
      for /F "tokens=*" %%N in ('wmic nic where "deviceid=%%I" get NetConnectionID ^| findstr /v /r  "^$ NetConnectionID"') do  (
        Rem Enable Dhcp using lan connection name Ex.: Wireless Network Connection or Local Area Connection
    	CALL :ENA-DHCP %%N
    	Rem *** Set DNS for the adapter with Index  equal to %%I
    	CALL :SET-DNS "%%I" "8.8.8.8" "1.2.3.4"
      )
    )
    goto :EOF
    
    :ENA-DHCP
    	set nicname=%*
      	netsh interface ipv4 set address name="%nicname%" source=dhcp  1>nul 2>nul
    goto :EOF
    
    :SET-DNS
        REM *** Nic Index %~1  primary dns %~2   secondary dns %~3
        wmic nicconfig where (IPEnabled=TRUE and DHCPEnabled=TRUE and index=%~1) call SetDNSServerSearchOrder(%~2, %~3) 1>nul 2>nul
    goto :EOF
    :NotVistaOr7


    Gastone Canali >http://www.armadillo.it

    Se alcuni post rispondono al tuo quesito (non necessariamente i miei), ricorda di contrassegnarli come risposta e non dimenticare di contrassegnare anche i post utili . GRAZIE!



    Sunday, May 20, 2012 2:18 PM
  • Gastone - read it again.  The question seams to be to cjange the DNS settings to use DHCP when the the staic IP is changed to DHCP.

    Again - your code cannot be run remotely.  And the method will not set DNS to use DHCP settings as it sets a static DNS list.

    Try the follwoing:


    WMIC /NODE:server01 nicconfig  where (IPEnabled=TRUE and DHCPEnabled=TRUE) call SetDNSServerSearchOrder()


    ¯\_(ツ)_/¯

    Sunday, May 20, 2012 4:17 PM
  • I think is different Interpretations  ... (remote/local/dhcp/static ip &  dns /dhcp & dns static...)

    JRV say "What you are asking is not very clear. " &  GAS say "If I understood your question correctly you want enable the DHCP and setting maually the DNS."

    gwmi win32_networkadapterconfiguration -filter 'index=8'     is  my Microsoft ISATAP Adapter


    Gastone Canali >http://www.armadillo.it

    Se alcuni post rispondono al tuo quesito (non necessariamente i miei), ricorda di contrassegnarli come risposta e non dimenticare di contrassegnare anche i post utili . GRAZIE!


    Sunday, May 20, 2012 5:49 PM
  • Normally when we set DHCP we also want to set teh DNS to takes its settings from DHCP.  There is not clear documentation on how to do this.  The usual question is "How do I check the box for 'Obtain DNS Servr address automiatically'?"

    The answer is that ther eis no way to directly check or uncheck that box.  It is provided as a convenience in the GUI.  In WMI we must remove the DNS Server search list.  If we st one of more servers in teh array teh box will becomw unchecked and teh other box willbe chaecked.

    When mving from satic addressing it is always necessary to clear the server search list so DHCP can be the source for all settings which is one of the main reasons for using DHCP in the first place.

    Most often this is done remotely.  PowerSHell and WMI make this very easy.  First remove DNS then 'EnebleDHCP'.  Now restart the remote system and it will reset correctly.  In the past I have copied exisiting addresses to reserved settings in DHCP before resetting teh system.  Tis allows the system/server or retain its original address.  I don't like to do this but sometimes it is necessary untl we get all systems aware of teh use of DHCP.

    Domain Controllers, DHCP Servers and DNS Servers need to use static addresses.  Most other servers do not.


    ¯\_(ツ)_/¯


    • Edited by jrv Sunday, May 20, 2012 6:01 PM
    Sunday, May 20, 2012 6:01 PM
  • As there has been no activity in this thread for a few days, we assume the issue is resolved. We will mark it as "answered" to assist others in similar situations. If you disagree, please reply with further information. You can unmark the answer if you wish. If a reply helped answer your question, please mark it as the answer.


    Richard Mueller - MVP Directory Services

    Thursday, May 31, 2012 1:25 AM