GCP Private IP change for instance - google-cloud-platform

In GCP if an instance is having an private ip does the private ip change if we restart or stop and start the instance. And also if it does not change what is the use of reserving a static internal ip address. Thanks

As stated in the restriction You cannot unassign or change the internal IPv4 address of an existing resource
Reserving an internal IP address takes that address out of the dynamic allocation pool and prevents it from being used for automatic allocations.
If a VM instance requires a fixed Internal IP Address to a Static one, you can also reserve it. Each VM interface has one primary internal IPv4 address, which is assigned from the subnet's primary IPv4 range.
With the ability to reserve static internal IP addresses, you can always use the same IP address for the same resource even if you have to delete and recreate the resource.
Deleting a resource does not automatically release a static internal IP address.

Related

Accessing EC2 instance with DNS

I have an instance inside a VPC with DNS hostnames & DNS resolution enabled
Today, each instances I spawn get the hostname & Private IP DNS name as
ip-xx-xx-xx-xx.ec2.internal
The problem with this is everytime my instance is terminated and I have to replace it, the IP address is going to change. Other machines in the same VPC need a deterministic way to access this instance. e.g. by connecting to mymasterinstance.dev. Any idea how do I give an internal / private DNS for my instance?
Private IP addresses on Amazon EC2 instances do not change. Therefore, the other machines could simply reference the private IP address.
Alternatively, you can create a "Private hosted zone" in Amazon Route 53 and create an A-Record to associate a domain name (eg mymasterinstance.dev) with the private IP address of the instance.
The public IP address on an instance will change when the instance is Stopped and Started (but will not change when the instance is Rebooted). If you require a static public IP address, you can create an Elastic IP Address and associate it with the instance.
Another perhaps simpler way to do this is to add a second IP address to your EC2 instance. When you terminate an instance, and add back a "replacement" instance, set its second IP address to what the terminated instance's second IP address was. Then you can do all of your referencing directly by IP address and you have full control over that second IP address. None of your configs needs to change.

How long does it take to release the ephemeral IP address back to the GCE pool?

Ephemeral external IP addresses: these addresses are available to VM
instances and forwarding rules. Ephemeral external IP addresses 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 were assigned to the instance are
released back into the general Compute Engine pool and become
available for use by other projects. When a stopped instance is
started again, a new ephemeral external IP address is assigned to the
instance.
I have thought is instantaneously and we won't be getting back the same ephemeral IP address once the VM is stopped. However, it seems that ephemeral external IP addresses will still be assigned to a project for a while longer. For instance, I deleted a VM and released an IP address two days ago. The same IP address is assigned to a new VM today.
How long does it take to release the ephemeral IP addresses back to the GCE pool?
Are the ephemeral external IP addresses "assigned" to VPC or Project? If one has multiple projects within a VPC, will the ephemeral IP addresses be rotated within the projects until they are released to the GCE pool?
The answer is "it should not matter if ephemeral addresses are reused for your instance or not".
There is no guarantee that your instance will obtain the same address or will not obtain the same address. If you are designing something that depends on a certain ephemeral IP address behavior, your design will fail at some point.
Your question quotes Google's official ephemeral IP address policy. Design to that statement and do not depend on environment level behavior.
If you require a fixed IP address, then assign your instance a static IP address. Otherwise, your instance will have whatever address Google Cloud decides, which may or may not be the same address between restarts or recreates.
If your goal is to randomize public IP addresses, then you cannot count on the ephemeral address behavior to implement that. You can allocate a set of static IP addresses and then change which one is assigned to an instance. Note that unused IP addresses are billed (not free). Another method is to create instances in different regions and zones which will have different public IP addresses. You also could write a script to create VMs until the address is different (not part of a previous set of addresses) and then delete the other VMs (subject to quota restrictions).
From a customer support perspective, it is to Google's benefit to reallocate the same address to you. This minimizes a common problem. Some customers do not understand that the default IP address is ephemeral and what that means. They reboot their instance and the IP address changes. That breaks their SSH scripts, DNS settings, etc. The ephemeral address behavior cannot be consistently deployed but is a positive where possible.
Answers to your questions -
It’s instantaneous.
Ephemeral addresses don't belong to any project and can be assigned to any resources across projects, randomly.
Some users have done some tests like this and concluded that the system tends to assign familiar IP addresses to VMs if it can. However, this is not something confirmed by GCP. Regardless, it’s of no use as there is no guarantee what IP address you’ll be getting.

TTL of Dynamic Private IP Address for Azure VMs?

What's the time to live for private IPs that are dynamic and assigned to NICs for Azure based VMs?
You can see the description of the dynamic IP address here:
Once assigned, dynamic IP addresses are only released if a network
interface is deleted, assigned to a different subnet within the same
virtual network, or the allocation method is changed to static, and a
different IP address is specified. By default, Azure assigns the
previous dynamically assigned address as the static address when you
change the allocation method from dynamic to static.
So it means if you do not delete or change the configuration of the network interface of the VM, then the dynamic IP address will work as the static IP address.

Is there away to change previous domain address to newly assigned elastic ip address

Is there a way to reconfigure the previous instance's IP address to the newly assigned IP address.
After I configured all my instance and I tried to assign the elastic IP. I found that the IP is changed. therefore the website under apache2 /var/www/html was no longer valid / unreachable.
is there any way that I can change old IP to new IP address?
NEW: ec2-13-237-246-127.ap-southeast-2.compute.amazonaws.com
will redirect to
OLD:http://ec2-54-206-98-171.ap-southeast-2.compute.amazonaws.com/
since I changed to associate a new IP into this instance.
Unfortunately, you can not reuse that public IP address.
A public IP address is assigned to your instance from Amazon's pool of public IPv4 addresses, and is not associated with your AWS account. When a public IP address is disassociated from your instance, it is released back into the public IPv4 address pool, and you cannot reuse it.
If you require a persistent public IP address that can be associated to and from instances as you require, use an Elastic IP address instead
The old DNS will not be available. These DNS entries are auto generated by AWS. If you notice the format, you would see,
ec2-<ip-address>.<region>.compute.amazonaws.com.
If you want a static DNS name, you must created a domain, add an address record pointing to your instance's public IP.

Elastic IP Address is being dissociated after a restart

I have an EC2 Instance with a Public IP associated.
For no reason, after a restart, this association is lost and I have to reassociate.
It doesn't happen for every restart.
Any tips?
There are two types of public IP addresses available for Amazon EC2 instances:
A Public IP address that is randomly assigned to an instance from a pool of available addresses. If an instance is stopped and later started, it might receive a different public IP address. (Restarting an instance will not cause this to happen, so I suspect that you stopped your instance rather than merely restarted it.)
An Elastic IP address that can be allocated to your account. The address can then be allocated to an EC2 instance. The IP address is static, so it will not change. However, it can be reassigned to a different EC2 instance if desired. It remains associated with the account until it is released.
If you are saying that you were using an Elastic IP address, then it should remain associated with the instance until specifically dissociated. It will not dissociate without a specific request. If it is being dissociated, then you could use AWS CloudTrail to look for the API call that would have caused this to happen.
In AWS EC2, By default the EC2 instances are not assigned with static public IP address.
For that, you will have to generate a Static IP address first and then assign it to your EC2 instance. In this way, even after the restart, it will retain the allocated static IP address.
To do this, Navigate to EC2 service, select 'Elastic IPs' from the left menu. Click on Allocate Elastic IP address. This will generate the static IP address. Now to allocate this to your instance, select the checkbox against the newly generated IP address, and click on Actions and 'Associate Elastic IP address'
Hope this helps :)