Serverspace Black Friday
SF
April 27, 2023
Updated May 25, 2023

Configure Windows with multiple IP Addresses via PowerShell

Networks Windows

In some cases, for example, on web servers, it is required to configure more than one IP address on one network adapter. If this is one server and it has one or two network cards and a small number of additional IP addresses, then, as a rule, configuration through the graphical interface will not cause problems. But what if there are more than ten servers, and each has several network adapters with a whole bunch of IP addresses? In this case, setting up via the graphical interface will take a lot of time. In this case, Windows automation tools PowerShell will come to the rescue. Next we will consider the configuration process for the Windows Server 2016/2019 OS.

First you need to run Powershell as an administrator. You can do this by right-clicking on the "Start" menu and selecting "Windows PowerShell (Admin)" in case of an English version of OS:

Start PowerShell as Administrator
Screenshot №1. Start PowerShell as Administrator

Next, a PowerShell window will open. Now you need to determine on which interface you need to add the required IP addresses.

Using below command, we determine the required network interface:

Get-NetAdapter
Determine network adapters for setup
Screenshot № 2. Determine network adapters for setup

In this case, one network adapter named "Ethernet", and we will use it. Let's first find out which IPs are already configured on this adapter using the command :

Get-netIpAddress -ifalias Ethernet -addressFamily Ipv4 | ft
Find out which IPs are already configured
Screenshot № 3. Find out which IPs are already configured

To add a new address, for example 192.168.10.10, you must use the following command:

New-NetIPAddress -addressfamily Ipv4 -IPAddress 192.168.10.10 -PrefixLength 24 -InterfaceAlias “Ethernet” -SkipAsSource $True

Check the result by running this command below:

running command New-IPAddress
Screenshot № 4. Result by running command New-IPAddress

As you can see, the adapter has been assigned another IPv4 address — 192.168.10.10. If you want outgoing traffic to be sent from the added IP address, you need to change parameter as below :

Set outgoing traffic to be sent from the added IP address
Screenshot № 5. Set outgoing traffic to be sent from the added IP address

If you need to add a larger number of addresses, for example 5, then you can use the script. Using an array of numbers, for example, from 11 to 16 and a foreach-object loop, add 5 more IP addresses:

11..16 | foreach-object {New-NetIpAddress -ifalias Ethernet -AddressFamily IPv4 -PrefixLength 24 -IPAddress "192.168.10.$_" -verbose}
Adding multiple IP by script
Screenshot № 6. Adding multiple IP by script

After executing the command, check with the already familiar command:

Result after executing script
Screenshot № 7. Result after executing script

Conclusion: In this article, we looked at the possibilities of using PowerShell to automate the assignment of multiple IP addresses on a single network interface.

Vote:
5 out of 5
Аverage rating : 5
Rated by: 2
33145 North Miami, FL 2520 Coral Way apt 2-135
+1 302 425-97-76
700 300
ITGLOBAL.COM CORP
700 300
We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.