How to set static IP address and DNS Server using Command Line in Windows 10

Repeatedly having to change your Static IP address when shifting from one network to another can be a pain in the neck. The process is lengthy on Windows 10 and a bit irritating. If you are the person who needs to switch between IP addresses, then this article is for you.

Here we shall show you how you can configure your system’s IP address directly through the command line interface on your Windows 10 platform. It is very less time consuming and can be done in a few steps.

The IP address is a unique identifier of your machine that lets every other component on the network know where the packets need to be routed to. Since it is unique, it cannot conflict with another IP address on the same network.

Configure Static IP address and DNS Server using PowerShell in Windows 10
Configure Static IP address and DNS Server using PowerShell in Windows 10

You can manage your IP address by both the Command Prompt and the PowerShell, which shall be discussed further in the article.

If you are looking for a way to instantly switch between different network profiles, you can make use of NetSetMan 5.

How to check Interface Index using PowerShell

The Interface Index is a unique number assigned to either a physical or virtual networking port. Each port is assigned a number that is used to address the respective port on the machine. For example, if there are 5 different networking adapters on a computer, each one would have its own Interface Index.

To check the associated Interface Index for each, run the following command in PowerShell with administrative privileges:

get index

In the example above, the “ifIndex” is identified as the Interface Index. Note that the ports are repeated as the first half represents IPv6, while the 2nd half represents IPv4 configuration. Nonetheless, the Interface Indexes of the same ports are the same.

Note down the associated Interface Indexes as they will be required when assigning static IPs through PowerShell.

How to set static IP address using Command Prompt

These commands are relatively easier with the Command Prompt when compared with PowerShell. You can change the IP address of your computer using this quick command.

Launch the Command Prompt with administrative privileges and then use the command below to assign the desired IP address configuration:

netsh interface ipv4 set address name=”NameOfPort” static [IP address] [Subnet mask] [Default gateway]

In the above command, you need to place the information according to your requirement. Replace NameOfPort with the alias name of the network adapter you wish to set the IP of. Also, replace [IP address] with the IP address of the port you wish to assign, replace [Subnet mask] with its subnet, and replace [Default gateway] with the gateway of the adapter.

Here is an example:

netsh interface ipv4 set address name=”Ethernet” static

Since the name of my port is “Ethernet,” entering the command above would result in the following configuration:

ip set

How to set DNS address using Command Prompt

As you may have noticed above, we did not set up the DNS. This is because you need to enter a separate command to configure the DNS, which is as below:

netsh interface ipv4 set dns name=”Ethernet” static

This will set the first DNS entry as Note that this will only occur if the port can communicate with the DNS. Else it will throw an exception.

The above command would result in something like this:

dns 1 set

To change the second DNS server, use the following command:

netsh interface ipv4 set dns name=”Ethernet” static index=2
dns 2 set

Remember to change the port name, IP address, gateway, and subnet mask according to your requirement.

Each time you need to switch between your IPs and DNSs, use these commands, and it will automatically overwrite the previous entering.

How to set static IP address using PowerShell

Although the PowerShell command lines are more complex than those of the Command Prompt, they also offer more parameters to be addressed. However, we will try and keep it as plain and simple as possible.

Before we proceed further, you need to understand some terms to enter the correct parameters. Below are a few arguments and their descriptions used in PowerShell to set static IPs and DNS entries.

InterfaceIndexA unique number is assigned to each port
PrefixLengthSubnet mask
AddressFamilyEither IPv4 or IPv6
AsJobRun task in background

Now, modify the following command according to your needs, launch Windows PowerShell with administrative privileges and enter the command:

New-NetIPAddress -InterfaceIndex 6 -IPAddress -AddressFamily ipv4 -PrefixLength 24 -DefaultGateway -AsJob
PS 1

Note that we determined the correct Interface Index using the command we had discussed earlier in the article. This is what the IP configuration of the port would look like after running the command above:

PS ip set

How to set DNS address using PowerShell

You can also use PowerShell to assign DNS addresses as well quickly. In the example below, we have assigned both the primary and the secondary DNS addresses to our port simultaneously.

Set-DnsClientServerAddress -InterfaceIndex 6 -ServerAddresses ("","")
PS set dns

You may repeatedly use these commands in PowerShell to overwrite new IP address, subnet mask, gateway and DNS entries of any network port you want on your PC.

Closing words

Now you do not need to worry about switching from one network to another. You can make the process even quicker by saving the respective IP configuration on your PC and copy-pasting it to the command line when required to switch.

If, however, you run into a problem associated with your computer network, you may use this guide to reset the TCP/IP stack.

Subhan Zafar

Subhan holds a degree in Electrical Engineering and has completed several system and network certifications including Huwaei, Cisco and Microsoft certs. He mostly researches and writes about the Windows world.

2 thoughts on “How to set static IP address and DNS Server using Command Line in Windows 10

  1. I have been using netsh for more than 10 years now to switch between 2 ISP’s services. My only problem was the jokers at MS kept changing command line switches with every version of Windows. XP -> 7 -> 10. Why is something beyond me.

    1. Forgot to mention that I religiously avoid using power shell & work only with “Take Command” from JPSoft.

Leave a Reply

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

Recent Posts