Configuring a Static Internal IP Address for Windows Instances

This guide shows you how to configure a static IP address for a Windows instance using a loopback adapter. You only need a loopback adapter if you need an internal IP address that persists beyond the life of the instance.

If you just want to assign a specific internal IP address to an instance when you create the instance, read the Specifying an internal IP address at instance creation documentation instead.

By default, Compute Engine provides an ephemeral internal IP address to an instance when the instance is first created. An instance's internal IP address can change when the instance is deleted and recreated. If you need the internal IP address to persist beyond the life of the instance, you can use a combination of routes and the --can-ip-forward feature to configure a static internal IP address that can be addressable by other instances in the same network.

Before you configure a static internal IP address, keep in mind that it is also possible to communicate with an instance using the instance name. Even if the instance's internal IP might change, the instance name remains the same, so you can configure your applications to send packets to the instance name instead. Using an instance name is more reliable than configuring a static internal IP address if you do not explicitly need to use an IP address.

To assign a static IP address to a Windows virtual machine, use the Windows loopback adapter to enable connections between instances without having to go outside the network.

This example uses the following resource names:

  • example-windows-instance is the instance that will receive packets at the static IP address.
  • 10.1.1.1 is the static internal IP address assigned to the instance.
  • windows-static-route is the name of the network route to direct packets destined for 10.1.1.1 to example-windows-instance.

If you want to change any of the above parameters, replace each of the resource names in the following steps.

Set up an internal IP for a Windows instance

  1. Choose an internal IP address that is not part of any network range in the project.

    Use an address from a private range, like 10.x.x.x or 192.168.x.x, but not from a range that is in use in the project. This example uses 10.1.1.1.

  2. Create your Windows instance, with the --can-ip-forward property enabled.

    gcloud compute instances create example-windows-instance \
        --image windows-2008-r2 \
        --can-ip-forward
    
  3. Create a firewall rule to allow RDP connections.

    You should already have this rule in your project but if not, create a firewall rule to allow RDP connections so you can use remote desktop to connect to your virtual machine:

    gcloud compute firewall-rules create rdp --allow tcp:3389
    

    You can check your existing firewall rules by running:

    gcloud compute firewall-rules list
    
  4. Next, create a route that will direct packets destined for your static IP to your Windows instance.

    The target of the static route must be an IP address that is not in any network of the project.

    In this case, the static IP is 10.1.1.1/32.

    gcloud compute routes create windows-static-route \
        --destination-range 10.1.1.1/32 \
        --next-hop-instance example-windows-instance\
        --priority 1
    
  5. Log in to your Windows instance through an RDP client.

    You will need your Windows instance's external IP address, username, and password. If you do not have this information, see the Create and reset passwords.

    Start your RDP client, and use the external IP address to log in. When prompted, provide your username and password.

  6. Enable Windows Loopback Adapter.

    The loopback adapter will allow you to assign a static IP to the instance. While you are logged on to your Windows instance, follow these steps to install the loopback adapter.

    1. Click on the Start menu, type in Device Manager in the search box, and select Device Manager from the search results.
    2. In the Device Manager window, right click on the name of the virtual machine. For this example, right click on example-windows-instance.
    3. From the right-click menu, click Add legacy hardware. The Add Hardware wizard will appear.
    4. Click Next on the welcome screen.
    5. Select Install the hardware that I manually select from a list and click Next.
    6. From the list, select Network Adapter and click Next.
    7. Select Microsoft from the Manufacturer list, and select Microsoft Loopback Adapter from the Network Adapter list. Click Next.
    8. Click Next on the next screen and click Finish when the installation completes.
  7. Assign a static IP to your loopback adapter.

    1. From the Start menu, type Network and Sharing Center and select it from the list.
    2. On the Network and Sharing Center screen, click Change adapter settings on the left-hand menu.
    3. Right click on the adapter labelled with Microsoft Loopback Adapter and select Properties.
    4. Select Internet Protocol Version 4 from the list and click Properties.
    5. Select Use the following IP address and fill in the following information:

      • IP address: The static address you want to use. In this example, 10.1.1.1.
      • Subnet mask: 255.255.255.255

      Leave the rest of the boxes empty and click OK to save your settings.

    6. Click Close to close the properties window.

  8. Enable IP forwarding.

    1. From the Start menu, open up the registry editor. Type regedit.exe and select it from the search results.
    2. Expand HKEY_LOCAL_MACHINE > SYSTEM > CurrentControlSet > services > Tcpip > Parameters.
    3. Double click on the IPEnableRouter property, and change the Value data box to 1. This enables IP routing for the instance.
    4. Click OK.
  9. Reboot the virtual machine.

    From the Start menu, click the arrow next to Log off and select Restart. If prompted for a reason, select any reason.

To test that your configuration was successful, connect to another instance on the same network as your Windows instance and ping the following addresses:

  • The instance name, for example example-windows-instance.
  • The external IP of the instance.
  • The static IP of the instance, 10.1.1.1.

All of these destinations should return successful responses.

What's next

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

Compute Engine Documentation