GCP Cloud NAT
- Anand Nerurkar
- Sep 15, 2023
- 2 min read



create new project

create instance


above setting will make aure that vm does not have external ip address



we are trying to get update, but it wont b/c vm is having private ip , it can not connect to internet. so we will set up NAT
we need to first reserve ip addresses for the NAT, so goto vpc nw->ip addresses->reserve external ip address



goto cloud nat






now ssh to ur vm and get update , it shold work now

This is the default NAT Rule get applied so that it can connect internet and download update.


now VM make use of Cloud NAT and connect to internet and download update.
Cloud NAT Rule
==
This is the defaut rule created when you create Cloud NAT.

scenario
--
we need to connect to different 2 3rd party system from our vm , so we can set up routing rules as below
we will reserve 2 more static ip address for each 3rd party system above.
rule 1 - connect 1st 3rd party system with static ip 1
rule 2 - connect 2nd 3rd party system with static ip 2
else connect to default rule
step1
--
reserve ip addres as below

we will simulate 3rd party system with vm as below

we will deploy below python app into one of our vm

ssh into 3rd party vm as below

We have deployed python app to this 3rd party system and it is accessible on port 5000
so we need to create firewall rule for port -tcp-5000
now hit below url , you can see python app running


so both 3rd party system up and running
now we will set up cloud NAT rule for both 3rd party system as below


rule 2 for system2
==


ssh to instnace1 and hit 1st 3rd party url :5000

Thus when we hit 1st 3rd party ip address:5000, it make use of NAT rule and forward it to NAT Rule1
Comments