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:
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:
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 :
To add a new address, for example 192.168.10.10, you must use the following command:
Check the result by running this command below:
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 :
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:
After executing the command, check with the already familiar command:
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.