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
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-instanceis the instance that will receive packets at the static IP address.
10.1.1.1is the static internal IP address assigned to the instance.
windows-static-routeis the name of the network route to direct packets destined for 10.1.1.1 to
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
Choose an internal IP address that is not part of any network range in the project.
Use an address from a private range, like
192.168.x.x, but not from a range that is in use in the project. This example uses
Create your Windows instance, with the
gcloud compute instances create example-windows-instance \ --image windows-2008-r2 \ --can-ip-forward
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
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
gcloud compute routes create windows-static-route \ --destination-range 10.1.1.1/32 \ --next-hop-instance example-windows-instance\ --priority 1
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.
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.
- Click the Start menu, type in Device Manager in the search box, and select Device Manager from the search results.
- In the Device Manager window, right click the name of the virtual machine. For this example, right click example-windows-instance.
- From the right-click menu, click Add legacy hardware. The Add Hardware wizard will appear.
- Click Next on the welcome screen.
- Select Install the hardware that I manually select from a list and click Next.
- From the list, select Network Adapter and click Next.
- Select Microsoft from the Manufacturer list, and select Microsoft Loopback Adapter from the Network Adapter list. Click Next.
- Click Next on the next screen and click Finish when the installation completes.
Assign a static IP to your loopback adapter.
- From the Start menu, type Network and Sharing Center and select it from the list.
- On the Network and Sharing Center screen, click Change adapter settings on the left-hand menu.
- Right click the adapter labelled with Microsoft Loopback Adapter and select Properties.
- Select Internet Protocol Version 4 from the list and click Properties.
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.
Click Close to close the properties window.
Enable IP forwarding.
- From the Start menu, open up the registry editor. Type regedit.exe and select it from the search results.
- Expand HKEY_LOCAL_MACHINE > SYSTEM > CurrentControlSet > services > Tcpip > Parameters.
- Double click the IPEnableRouter property, and change the Value data box to 1. This enables IP routing for the instance.
- Click OK.
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
- The external IP of the instance.
- The static IP of the instance,
All of these destinations should return successful responses.