Jul 132008
 


In Windows Server 2008 Core installation, the only way to setup IP Address eithe Static or DHCP is from the command line. The following procedure helps setting the IP Address from the command Line using “netsh”. This procedure works in Windows Server 2008 (No core installation as well), Windows Server 2003, Windows XP, Windows Vista.

To setup Static IP Address:

From the command prompt:

1. Type 

C:\Users\Administrator> netsh interface ipv4 show interfaces
Idx  Met   MTU   State        Name
—  —  —–  ———–  ——————-
  1   50 4294967295  connected    Loopback Pseudo-Interface 1
 10   20   1500  connected    Local Area Connection

This should show the Network Connections. We are looking for the name here. On mine, I have one LAN interface and is named as “Local Area Connection”

2. To set a static IP Address type the following command

C:\Users\Administrator>netsh interface ipv4 set address name=”Local Area Connect
ion” source=static address=192.168.0.5 mask=255.255.255.0 gateway=192.168.0.1

The syntax is

netsh interface ipv4 set address name=”<ID>” source=static address=<StaticIP> mask=<SubnetMask> gateway=<DefaultGateway>

Where:
ID is the name of the LAN Connection
StaticIP is the static IP address that you are setting
SubnetMask is the subnet mask for the IP address
DefaultGateway is the default gateway

3. Now set the DNS Servers one at a time with the followind command. For each DNS server, increase the index number.

C:\Users\Administrator>netsh interface ipv4 add dnsserver name=”Local Area Conne
ction” address=192.168.0.1 index=1

C:\Users\Administrator>netsh interface ipv4 add dnsserver name=”Local Area Conne
ction” address=192.168.0.10 index=2

The syntax is

netsh interface ipv4 add dnsserver name=”<ID>” address=<DNSIP>index=1

Where:
ID is the name of the Network Connection
DNSIP is the IP address of your DNS server

This should do. To confirm, do an “ipconfig”

Ethernet adapter Local Area Connection:

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Broadcom 440x 10/100 Integrated Controller
   Physical Address. . . . . . . . . : 00-1D-09-D4-2C-8F
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes
   IPv4 Address. . . . . . . . . . . : 192.168.0.5(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.0.1
   DNS Servers . . . . . . . . . . . : 192.168.0.1
                                       192.168.0.10
                                       127.0.0.1
   NetBIOS over Tcpip. . . . . . . . : Enabled

Set IP through DHCP Server

To set the DHCP Server, from the command line

C:\Users\Administrator> netsh interface ipv4 set address name=”Local Area Connection” source=dhcp

Syntax is

netsh interface ipv4 set address name=”ID” source=dhcp

where ID is the name of the Network Connection

Incoming search terms:

  16 Responses to “How to set Static/DHCP IP Address from command line”

  1. I doesnt work!

  2. It doesnt work!

  3. This applies to only windows 2008 and vista boxes. But if you want to do it on a windows 2003, it is like this:

    To set/change IP and default gateway the command is

    netsh int ip set address “local area connection” static 10.0.0.3 255.0.0.0 10.0.0.1 1

    To change or set DNS ip

    netsh int ip set dns “local area connection” static 10.0.0.3 primary

  4. To set DHCP IP through command on windows server 2003

    netsh int ip set address “local area connection” source=dhcp

    Please note that these commands (mentioned in my previous comments as well) applies to xp as well.

    Do not forget to run “ipconfig /renew” command after running the above netsh to get an ip from the DHCP.

  5. Thank you for this explanation it works perfectly!

  6. How would you use this method when trying to add a /26 block of public ip addresses?

  7. Hello,
    I am also facing an issue when I try this command in SBS 2008 Prem this gives me an error
    The interface is unknown

    Here is my command correct me if I am wrong I tryed both

    netsh interface ipv4 set address name=”Local Area Connection” source=static address=10.10.168.203 mask=255.255.255.0 gateway=10.10.168.1

    netsh interface ipv4 set address name=”Local Area Connection 2” source=static address=10.10.168.203 mask=255.255.0 gateway=10.10.168.1

    • In the Windows restore environment, to get the netsh command to actually work, you must first run “wpeinit”.
      THEN netsh can assign the IP address.

  8. What if we dont know what the network connection name is? Not all computer have the same network connection name. What should be typed, in order to make the netsh for example, change all dns of wireless lan connection it found on the computer?

    • Agree – I know how to FIND The connection name, but I’m trying to write a script, and automate a DNS change via a startup script GPO to overwrite the DNS entries for an upcoming DNS change..

      SOME of my servers still have “Local Area Connection” type names, but some machines have been renamed to reflect a VLAN number, or a public NIC team, or something, so the NIC names will be inconsistent… I’d like to be able to do something like:

      netsh interface ip add dns name=* addr=1.2.3.4

      but that doesn’t seem to work..

      Any hints?

      Thanks!

      Steve

  9. Sweet:)

    Works awesome

    Can anyone tell me the way to set a third Dns IP for 2003 or older…… would it like trinary( can’t remember 3 in that context) and 4 if you can:)

  10. Hi,

    The command line instructions provided to set a static IP and revert it to DHCP is really helpful. This helps me to get in to office network and then back on DHCP when at home to connect to ISP.

    Thank you very much.

    -Ramesh Anna

  11. To check the name of your network connection, use the following command:
    ipconfig
    From the details supplied, find the connection you want to change and the name is after the “Ethernet Adapter”.

  12. how can i set the 4 dns in command line of win vista and win2003?

  13. I just used this for setting up a Windows Core server for my Windows Server Administrator class. You are a real life saver :D

    Thank you very much <3

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>