Configure Static IP using PowerShell
So let us dive right in. To start, make sure you open an administrator PowerShell window, otherwise you will get an Access is Denied error when trying to run the command below.
We will be using two PowerShell commands, New-NetIPAddress and Set-DNSClientServerAddress.
On the server that we want to configure, we open PowerShell and type the below command:
-DefaultGateway -PrefixLength -InterfaceIndex (Get-NetAdapter).InterfaceIndex
New-NetIPAddress –IPAddress 192.168.1.13 -DefaultGateway 192.168.1.1 -PrefixLength 24 -InterfaceIndex (Get-NetAdapter).InterfaceIndex
All the arguments are self-explanatory, apart from the InterfaceIndex one. Over here instead of putting in the numerical value of the Interface Index, I just ran the Get-NetAdapter command inside my current command with filtering to output only the integer value of the Interface Index.
If you have multiple network adapters on your system, you can remove
the function and simply enter the numerical value corresponding to the
If the command completes successfully, we should get the result as shown below:
Now we have our IP Address, Subnet Mask and Default Gateway
configured. However, one thing is missing. These are the DNS Server
To configure the DNS Server addresses, we run the following command:
Set-DNSClientServerAddress –InterfaceIndex (Get-NetAdapter).InterfaceIndex –ServerAddresses
, , etc.
Set-DNSClientServerAdress –InterfaceIndex (Get-NetAdapter).InterfaceIndex –ServerAddresses 22.214.171.124.1