Search Tools Links Login

Setting the IP Address from the Command Line


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

About this post

Posted: 2022-03-23
By: dwirch
Viewed: 424 times

Categories

Tip

Windows Commandline

Powershell

Windows

PowerShell Code Cache

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.