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.
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:
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 192.168.10.22 255.255.255.0 192.168.10.1
Since the name of my port is “Ethernet,” entering the command above would result in the following configuration:
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 126.96.36.199
This will set the first DNS entry as 188.8.131.52. 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:
To change the second DNS server, use the following command:
netsh interface ipv4 set dns name=”Ethernet” static 184.108.40.206 index=2
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.
|InterfaceIndex||A unique number is assigned to each port|
|AddressFamily||Either IPv4 or IPv6|
|AsJob||Run 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 192.168.0.1 -AddressFamily ipv4 -PrefixLength 24 -DefaultGateway 192.168.0.5 -AsJob
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:
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 ("220.127.116.11","18.104.22.168")
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.
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.