Google Compute Engine How to bind new external IP address to the instance - google-compute-engine

I need to get new external IP address every time when I recreate my instance.
Current implementation may use previous ips.
How can I achieve the goal with static or ephemeral ips?
Or how can I get GCE ips pool?

I am adding bellow information with Kolban.
For the external IP Google cloud has two categories:
Static external IP addresses
Ephemeral external IP addresses
The basic difference between these two are Static one is long term assignment until hey are explicitly released from that assignment, and remain attached to a resource until they are explicitly detached. Where, Ephemeral remain attached to a VM instance only until the VM is stopped and restarted or the instance is terminated. If an instance is stopped, any ephemeral external IP addresses that are assigned to the instance are released back into the general Compute Engine pool and become available for use by other projects.
As you are wishing for the new IP address for your instance, it seems Ephemeral external IP addresses is a better choice. But you can use the Static external IP addresses to create an IP pool anyway and rotate your reserved static external IP address, which has cost implications.
The external IP are configured in the accessConfigs. You can see accessConfigs if you describe your instance by below command in cloud shell.
$ gcloud compute instances describe [INSTANCE_NAME] --zone=[ZONE]
You can create a new VM and assign a static IP with the help of the Document and below command.
$ gcloud compute instances create [INSTANCE_NAME] --private-network-ip [IP_ADDRESS]
OR
You can change or assign an external IP in your existing VM following the steps of the document (GCLOUD), which are:
[Optional] Reserve a static external IP address (if you want to have the reserve external IP and this has cost implications).
Delete existing access configs.
Add the new external IP address.

When you create a Compute Engine instance and give it a public IP address you have two choices for that IP. It can either be ephemeral ... this means that the IP address is assigned (randomly) by Google and may change the next time the Compute Engine is restarted. The alternative is that it is static. These are IP addresses that Google fixes for you and are explicitly yours until you release them. There is no charge for a static IP address if it is actively being used (eg has a Compute Engine running that is using it). However if unused, you are charged 24 cents a day (1 cent an hour).
If, for some reason, you need a new IP address for a compute engine on demand, you can reserve a new static IP address and associate that with your compute engine.
See also:
Reserving a static external IP address

Related

Moving static IP Address on GCE without teardown

I'm replacing a legacy GCE VM with an static external IP address with a new VM with that same address.
I want to validate that the new VM works before moving the external IP address to the new machine and tearing down the old one.
Is there a way to do this without downtime and tearing down the old VM?
I found an answer on my own. This can be done through the following steps:
Going to the old VM and stopping it as an external IP cannot be released if it's in use.
Then go to IP addresses within that VPC network and select Release Static Address.
Reserve that IP address and assign to the new VM.
Note that these steps cannot be performed without downtime of the old VM as it will need to be stoped to release it's IP address.
Ideally this should be setup using a domain and a DNS A record instead.

Google Cloud - Adding additional Internal IP to VM

I'm trying to build a webserver in Google Cloud Platform that hosts multiple websites (GBP, IE, FR, DK etc.)
Generally, we assign a range of IPs to the server statically, set the bindings in IIS, then loadbalance using a virtual IP.
It seems near enough impossible to assign another internal IP in GCP. Lots of guides about additional external IPs, but we don't want a public facing webserver like this.
Anybody have any idea on how to add additional internal IPs to a VM / Instance?
Also, I have tried changing the internal address I have assigned to the Instance to static in network adapter settings, next thing I know I can't access my VM for love nor money, had to delete and re-create. If I go into advanced settings to add additional static IPs, w'ere set to DHCP apparently, so can't add additional IPs.
Thanks all.
Answer that I recieved from GCE discussion group, in Google Groups:
"You can add additional internal IP addresses to a VM instance. This is possible by enabling IP forwarding for the VM, creating a static network route, adding appropriate firewall rules, and setting additional internal IP addresses to network adapter of Windows. These steps are described in this article for Linux machines (https://cloud.google.com/compute/docs/networking#set_a_static_target_ip_address). The same steps are valid for Windows VMs. You will need to keep the initial internal IP address, subnet mask, gateway address and DNS settings of the adapter and manually enter them in properties of IPv4 of the network adapter. The below is a screenshot of my configuration on a VM instance (Windows 2008 R2) that perfectly works."
Update:
Now, you can create instances with multiple network interfaces On Google Compute Engine and assign IPs. For more information, refer to this public documentation link. However, currently it has following limitations:
Alias IP ranges are not supported on any network interface on a VM
that has multiple network interfaces enabled.
You cannot modify or delete the network interfaces after the VM has
been created.

Gcloud, Relase external IP

So I'm currently really new to google cloud platform and I have an issue to be solved.
I've already created a compute engine in gcloud. When it was created, it automatically assigned an external IP. I'd prefer the instances to not have any external IP.
I saw that you could put --no-address argument when creating the instances so it wouldn't be assigned an external IP, but how to release the external IP when the instance has already created?
> gcloud compute addresses list
NAME REGION ADDRESS STATUS
webserver europe-west1 130.211.70.XXX IN_USE
gcloud compute addresses delete 130....
Or use use 'network' tab in the web interface if it's a one-off need.

Hosting multiple websites in Google Compute Engine

We have 8 websites and 5 of them are small. I would like to host those 5 website in same instance but their ip must be same and static. I couldn't find a way how to allocate a static ip for each of them and how to host them in a single instance. They are PHP. Their db's are hosted in Google SQL.
Per the Google Compute Engine docs on static IP addresses:
An instance can have only one external IP address. If it already has an external IP address, you must first remove that address by deleting the old access configuration, then adding a new access configuration with the new external IP address.
That said, you don't need to have a separate static IP address per website—you can serve an arbitrary number of sites from a single VM by using a feature such as Apache virtual hosts which let you serve a different site depending on the hostname that is requested by the user.
This can be possible using Protocol Forwarding.
You can have different IP addresses for each website while using single Virtual Machine.
I had successfully hosted my 3 sites using method in past. If you need, I can write up a detail explanation on some blog.

On a google compute engine VM, is it possible to have a direct public ip instead of being behind a NAT?

Is it possible to have a public ip with direct access instead of being in NAT in a google compute engine virtual machine?
Thank you in advance.
You can have an external IP but by default the instance will have a NAT policy. If you need non-NAT'ed traffic, what you are looking for is a target instance because as stated in the documentation:
Target instances do not have a NAT policy applied to them.
After that, you can create forwarding rules to send traffic to your instance.
I hope it helps.
Static external IP addresses can be assigned to a compute engine VM.
You reserve a static external IP address in gcloud or through the API. After reserving the address, assign it to an instance during instance creation or to an existing instance. You will have to update the firewall to allow traffic on the port you want.
More info in the docs at:
https://cloud.google.com/compute/docs/instances-and-network#reservedaddress