Rotating IP on Google Cloud - google-cloud-platform

I have one instance on Google Cloud Compute engine. By default, it has 1 ephemeral external IP address.
I need to constantly change this external IP, ideally every 1-2 minute.
Is there any way to make this "IP rotation" by running some code?
Also, once new IP assigned, is there any way to get this IP by the code from the previous question and save it in external DB?
Update: Use case is to provide back-connect IP proxy server with IP rotation

This likely can be accomplished with add-access-config. As the documentation reads:
gcloud compute instances add-access-config is used to create access configurations for network interfaces of Google Compute Engine virtual machines. This allows you to assign a public, external IP to a virtual machine.
This lists external IP addresses (and indicates if they're currently assigned):
gcloud compute addresses list | grep external
Adding all IP adresses to a NIC and then rotating the address of a service might be less disruptive.

Related

Assigning domain name to Google Cloud VM

I'm attempting to assign a domain name to my Google Cloud VM external IP. I was following some walkthroughs and getting a bit confused. I set up apache with a simple "Hello" message when you visit my external IP. The walkthroughs I'm following are providing steps to reserve a new static external IP and creating a DNS zone.
Could someone provide clarification on why I would need to secure a new static external IP address when it appears I already have one assigned?
As discussed by #Ferregina Pelona in the comment section. The public IP that your VM already has is an ephimeral one which means that if the VM is stopped or restarted, there is a possibility this public IP changes. The problem will be that if it changes, your DNS will continue pointing to the old one which means your site will be not accesible until you update the DNS with the new IP. Reserving the public IP will warranty your VM always has the same IP.
Also, added by #DazWilkin. it should be more explicit in the documentation but I assume (!) it's an ephemeral IP. I submitted doc feedback for this.
I assume you're following a guide like [1]
The tutorial demonstrates the following steps when assigning a domain to a VM which would act as a server:
-Register a domain name using Google Domains or Cloud Domains
-Create a virtual machine (VM) instance
-Run a basic Apache web server
-Set up your domain using Cloud DNS
-Update name servers
-Verify your setup
However, there is a very important note that I believe clarifies completely the scenario you faced and the questions regarding this which states:
Note:By default, the VM instance that you create receives an ephemeral external IP address. Ephemeral external IP addresses are lost whenever the VM instance shuts down or reboots for any reason (for example, maintenance). To avoid shutdowns and reboots, use a static external IP address for web hosting. For instructions about how to reserve a static external IP address, see Reserving a static external IP address.
My suggestion would be that you try always to find an official docummentation according to the configuration/products you're expecting to use so as shown in this section, these are the advices that could avoid you yo fall into errors while moving forward. I hops this info make sense for you...
Cheers,

Multiple IPs on a single GCE instance

I want to have a VM with multiple internal IPs each with a one-to-one relation to external IP address on a single network interface.
I need to be able to initiate requests from that VM (single process) but need that different requests use different external IPs.
E.g.
10.146.0.3 <> 35.215.6.3
10.146.0.4 <> 35.215.6.6
10.146.0.5 <> 35.215.6.8
I managed to add multiple IPs to a single interface using alias IP ranges but can't find a way to map those extra internal IPs to external IPs.
This can be done quite to be easily done on AWS (took me about 5-10 minutes) as shown here, but after two full days looking around, I still can’t find a way to do this at GCP.
I am not looking for load balancing functionality or for any inbound connection related functionally (my VM acts as an HTTP client, not a server, so I only care about outbound connections). Also, if possible I also want to avoid multiple network interfaces as they are limited by 1 per vCPU and therefore don’t scale well cost-wise (plus all the hassle of having to create new VPCs).
Related questions (which don't quite solve my problem):
How do I setup 1 to 1 NAT in google cloud?
Multiple IP addresses on a single Google Compute Engine instance
How to assign multiple outgoing IPs addresses to a single instance on GCE?
For testing, I am using the following command:
curl -w '\n%{local_ip}\n' --interface <internal_ip> ifconfig.co
Which returns the external IP followed by the internal IP:
52.196.168.76
172.31.24.253
It's possible to add multiple external static IP addresses to a VM instance. Each VM instance can have up to eight network interfaces and you can assign a static external IP to the added interfaces.
However, is not possible to add the same NIC more than one to the same VM Instance and each added NIC subnetwork IP ranges cannot be overlapped. Each internal IP range got to be different1.
You may consider using a VM-appliance2 with multiple external IP addresses, useful for traffic separation as you intend to do.

External IP is not get visible on my compute engine dashboard

External IP does not get visible for my one of the compute engine
You may have not reserved an external static IP. You can do it through the Google console using an ephemeral IP address1 or assignnating one custom IP address mannually.2
If your issue is more related to the Google Console UI, try to check if there is a reserved external IP address for your particular VM instance by using the Google Shell and the following command:
$ gcloud compute instances list
You will need to provide more details about whats exactly is your issue.

How do you change your external ip?

What im trying to do is bypass ip detection from websites that i crawl.
Each website limit the amount of times per day you can crawl the site.
They limit your actions by reading your ip.
I use virtual machine (gcloud) to do my crawling so i won't keep my personal pc running.
When this happens, the website puts a block because of my ip.
Im trying to bypass this detection by getting a new ip.
My vm everytime i stop and restart the instance gives me the same 2 external ip addresses.
And in gcloud i thought since the setting was not static and set to ethereal, they would give you a new ip each time you stop the instance, but no.
They only flip flop between the same 2 external ip addresses.
I've learned that in my vm, the external ip is the ip websites look at to see if this address has been here before.
If i can continuously get a new address (like every time i stop the vm) i can keep crawling the websites.
BUT, the vm only gives me the same 2 external ip addresses... I've read that there is a shell command where you can demand a new ip but i do not know how to do this.
I would recommend you to assign a static IP to your VM and change it when you need to do it for your use case. You can change or assign an external IP address, either ephemeral or static, to an existing instance by modifying the instance's access configuration.

How to add extra private IP's to a GCP instance?

I want to add multiple routable ip addresses to an ubuntu 14.04 GCP instance. What is the simplest method for achieving this?
Note: External IP addresses are disabled on my gcp instances.
Correct me if I am wrong, but the solution described in this post that uses gcloud routes seems to change the network and firewall configuration to add extra IP addresses to instances. I am looking for a different solution.
I would like to add IP addresses to instances without changing the networks or firewalls of a gcp project at all.
I would like to add random available IP addresses on the current network of a gcp instance and avoid manually assigning an IP address or IP address range to my instances?
I am really looking for a solution that is similar to openstacks nova add-fixed-ip command that does just this. You can find a description of nova add-fixed-ip here: https://ask.openstack.org/en/question/65198/how-to-assign-static-private-ip-address-to-a-running-guest-vm/