Configuring Windows to Use a Secondary IP Addresses

Configure the Windows OS to use a secondary private IP.

After assigning a secondary private IP to a VNIC, you must configure the OS to use it. Here are instructions for using a PowerShell script or the Network and Sharing Center UI.
Using a PowerShell Script

You must run PowerShell as an administrator. The script configures two things: static IP addressing on the instance and the secondary private IP. The configuration persists through a reboot of the instance.

  1. In your browser, go to the Console, and note the secondary private IP address that you want to configure on the instance.
  2. Connect to the instance, and run the following command at a command prompt:

    ipconfig /all
  3. Note the values for the following items so you can enter them into the script in the next step:

    • Default Gateway
    • DNS Servers
  4. Replace the variables in the following PowerShell script with your own values:

    $netadapter = Get-Netadapter -Name "Ethernet 2"
    $netadapter | Set-NetIPInterface -DHCP Disabled
    $netadapter | New-NetIPAddress -AddressFamily IPv4 -IPAddress <secondary_IP_address> -PrefixLength <subnet_prefix_length> -Type Unicast -DefaultGateway <default_gateway>
    Set-DnsClientServerAddress -InterfaceAlias "Ethernet 2" -ServerAddresses <DNS_server>
    

    For example:

    $netadapter = Get-Netadapter -Name "Ethernet 2"
    $netadapter | Set-NetIPInterface -DHCP Disabled
    $netadapter | New-NetIPAddress -AddressFamily IPv4 -IPAddress 192.168.0.14 -PrefixLength 24 -Type Unicast -DefaultGateway 192.168.0.1
    Set-DnsClientServerAddress -InterfaceAlias "Ethernet 2" -ServerAddresses 203.0.113.254
    
  5. Save the script with the name of your choice and a .ps1 extension, and run it on the instance.

    This image shows the PowerShell script for configuring a secondary private IP address.

    If you run ipconfig /all again, you'll see that DHCP has been disabled and the secondary private IP address is included in the list of IP addresses.

Later if you want to delete the address, you can use this command:

Remove-NetIPAddress -IPAddress 192.168.11.14 -InterfaceAlias Ethernet

Also make sure to delete the secondary IP from the VNIC. You can do that before or after executing the above command to delete the address from the OS configuration.

Using the Network and Sharing Center UI

The following instructions configure two things: static IP addressing on the instance and the secondary private IP. The configuration persists through a reboot of the instance.

  1. In your browser, go to the Console, and note the secondary private IP address that you want to configure on the instance.
  2. Connect to the instance, and run the following command at a command prompt:

    ipconfig /all
    This image shows the results of the ipconfig /all command.
  3. Note the values for the following items so you can enter them elsewhere in a later step:

    • IPv4 Address
    • Subnet Mask
    • Default Gateway
    • DNS Servers
  4. In the instance's Control Panel, open the Network and Sharing Center (see the image below for the set of dialog boxes you'll see in these steps).
  5. For the active networks, click the connection (Ethernet).
  6. Click Properties.
  7. Click Internet Protocol Version 4 (TCP/IPv4), and then click Properties.
  8. Select the radio button for Use the following IP address, and then enter the values you noted earlier for the IP address, subnet mask, default gateway, and DNS servers.

    This image shows the series of dialog boxes you'll encounter.
  9. Click Advanced....
  10. Under IP addresses, click Add....
  11. Enter the secondary private IP address and the subnet mask you used earlier and click Add.

    This image shows the dialog box for adding the secondary private IP address.
  12. Click OK until the Network and Sharing Center is closed.
  13. Verify the changes by returning to the command prompt and running ipconfig /all.

    You should now see that DHCP is disabled (static IP addressing is enabled), and the secondary private IP address is in the list of addresses displayed. The address is now configured on the instance and available to use.

    This image shows the results of the ipconfig /all command after you've added the secondary private IP address.
    Note

    You might not see the primary private IP address when you again view the properties for Internet Protocol Version 4 (TCP/IPv4) in the Network and Sharing Center UI. The best way to confirm your changes is to use ipconfig /all at the command line.