Sometimes you get to the point that we need to reassign the instance on GCE with new external IP address. The cause can be varying starting for security and goes up other reasons. I've decided to summarize the process of re-assigning external IP address on GCE instance.
But first couple of side notes:
1) As GCE instance can have multiple IP addresses to get connections from using IP forwarding (see previous post of: How to assign multiple external ip addresses to instance in gce), at this point in time you can only assign a single external IP address for outgoing connections.
2) During the IP assignment your external connectivity to the server will be down
So how we do it?
Make sure all needed services and running process who needs external connectivity can stand a small downtime of you network interface.
Delete ephemeral/static external IP address from the instance by running the following command
$ gcutil --project=<project_name> deleteaccessconfig <your_instance> --access_config_name="External NAT" --network_interface_name=nic0
Step 3a (for ephemeral):
Assign an ephemeral external IP address to your instance by running the following command:
$ gcutil --project=<project_name> addaccessconfig <your_instance> --access_config_name="External NAT" --access_config_nat_ip=ephemeral --access_config_type=ONE_TO_ONE_NAT --network_interface_name=nic0
Step 3b (for static):
Assign a static external IP address to your instance (given that you have already reserved it, say 220.127.116.11), run the following command
$ gcutil --project=<project_name> addaccessconfig <your_instance> --access_config_name="External NAT" --access_config_nat_ip=18.104.22.168 --access_config_type=ONE_TO_ONE_NAT --network_interface_name=nic0
The process won't take more than 10 seconds, and you'll be assigned with a brand new IP address