Add Secondary IP Address Windows Server

Add Secondary IP Address

If you want to add a secondary IP Address without using the Change Adapter Options in the GUI ( especially on Windows Core servers ) you could use sconfig or simply add the IP address with PowerShell.

In my case, I wanted to add a secondary IP address to a certain interface on some Windows Server Core servers. Unfortunately, an Invalid Index error was thrown when I chose the appropriate interface under sconfig – Network Settings:

Invalid Index Network Settings

However, I faced this error a couple of months ago already when I wanted to Disable IPv6 in my test lab.

Because this time it was production servers I didn’t want to change any settings while adding secondary IP addresses to the servers. The only option was to add a secondary IP address via PowerShell.

… and here we go:

Add Secondary IP Address to Network Interface:

1 -List Network Interfaces with name and Interface Index

Get-NetAdapter

List Network Interfaces

2 -Display existent IPs on chosen Network Interface

To list IPv4 and IPv6 IP addresses:
Get-NetAdapter -ifIndex  ifIndex Number | Get-NetIPAddress | select IPAddress | ftList IPv4 and IPv6 addressesTo display only IPv4 addresses:
Get-NetAdapter -ifIndex ifIndex Number | Get-NetIPAddress | where {$_.AddressFamily –eq “IPv4”} | select IPAddress
List IPv4 addresses

3 -Add new IP address

New-NetIPAddress –IPAddress “IpAddress goes here” –PrefixLength 24 –InterfaceIndex ifIndex Number
Add secondary IP address
The command adds the IP address to the ActiveStore and the Persistent Store.
You can read more about the PolicyStore values here.

4 -Verify that add a secondary IP address was successful

Get-NetAdapter -ifIndex ifIndex Number | Get-NetIPAddress | where {$_.AddressFamily –eq “IPv4”} | select IPAddress
Add Secondary IP Address done!

Thats all. You don’t need to specify a default Gateway since this has most likely be done already with the initial IP address.

Remove IP Address from Network Interface:

1 -List Network Interfaces with name and Interface Index

Get-NetAdapter

Add Secondary IP Address list

2 -Display existent IP addresses that can be removed on chosen Network Interface

We focus here only on IPv4 addresses. See point 2 - above to display IPv6 as well.
Get-NetAdapter -ifIndex ifIndex Number | Get-NetIPAddress | where {$_.AddressFamily –eq “IPv4”} | select IPAddress
add secondary IP address remove
Copy IP address to remove from the output.

3 -Remove IP address

Insert copied IP address in the command below:
Get-NetIPAddress –IPAddress IPAddressToRemove –InterfaceIndex ifIndex Number | Remove-NetIPAddressYou will need to confirm it for both PolicyStores.
Otherwise you could use the command with -Confirm:$false

4 -add secondary IP address verify

Get-NetAdapter -ifIndex ifIndex Number | Get-NetIPAddress | where {$_.AddressFamily –eq “IPv4”} | select IPAddress
Add secondary IP address IPv4 addresses

I have compiled the above steps in a script to make it more convenient:

Script to Add/Remove IP Address

Leave a Reply

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