Setting IP addressing from the command line

There are two ways of configuring IP addresses from the command line one is using netsh and the other is using PowerShell 3 and above.

First you need to find what the interfaces are:

netsh interface ipv4 show interfaces

 

Idx Met MTU State Name
— ———- ———- ———— —————————
1 50 4294967295 connected Loopback Pseudo-Interface 1
3 20 1500 connected Ethernet

having determined the name of the interface is Ethernet you can set the ip with the following command

netsh interface ipv4 set address name=ethernet source=static address=192.168.9.1 mask=255.255.255.0 gateway=10.10.10.1

 

You can add a DNS server with

netsh interface ipv4 address dnsserver name=ethernet address=10.10.10.70 index=1

use index=2 for the secondary DNS server and so on.

 

Using  PowerShell

Get-NetAdapter

Name           InterfaceDescription                      ifIndex Status MacAddress LinkSpeed
—-               ——————–                              ——-  ——       ———-        ———
Ethernet     NVIDIA nForce Networking Controller 3 Up 00-19-21-D1-04-9C 100 Mbps

 

 

with PowerShell

Set-NetIPAddress -InterfaceIndex 3 -IPAddress 192.168.0.1 -PrefixLength 24

And for DNSress –InterfaceIndex 12 –ServerAddresses (“10.0.0.1″,”10.0.0.2”)

Set-DnsClientServerAddress –InterfaceIndex 3 –ServerAddresses (“10.0.0.1″,”10.0.0.2”)

Another way to do this it to use sconfig if you are on a core server. Window 2008 R2 and onwards.