Setting the IP Address from the Command Line

By | 2022-03-23

When you are building a Windows server from the command line, GUI interfaces are not available. Here are two methods of setting IP configuration from the command line.

Set IP Address Configuration with PowerShell

First, get the network adapter information with Get-NetAdapter:

PS C:\Users\Administrator> get-netadapter

Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
----                      --------------------                    ------- ------       ----------             ---------
Ethernet                  Microsoft Hyper-V Network Adapter             6 Up           00-15-5D-55-F4-0D       260 Mbps

Using the information from the output above, set the IP configuration of the interface (ifIndex):

New-NetIPAddress -InterfaceIndex 6 -IPAddress 192.168.1.199 -PrefixLength 24 -DefaultGateway 192.168.1.1
Set-DnsClientServerAddress -InterfaceIndex 6 -ServerAddresses 192.168.1.2, 192.168.1.3

Set IP Address Configuration with NetSh

First, get the information needed by displaying the installed interfaces:

PS C:\Users\Administrator> netsh interface show interface

Admin State    State          Type             Interface Name
-------------------------------------------------------------------------
Enabled        Connected      Dedicated        Ethernet

Using the Interface Name information from the output, configure the interface:

Netsh int ipv4 set address "Ethernet" static 192.168.1.199 255.255.255.0 192.168.1.1
Netsh int ipv4 set dnsserver "Ethernet" static 192.168.1.2 primary
Netsh int ipv4 set dnsserver "Ethernet" static 192.168.1.3 secondary

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.