Open In App

How to Use Cloud NAT For Outbound Internet Access on GCP?

Last Updated : 18 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

NAT Gateway is a Network address translation gateway that enables multiple devices to access a public network through a single IP address. It is mainly used to conserve registered IP addresses and use private IP addresses instead. Cloud NAT is used to expose internal private resources to the internet. We will see step by step process to do the same.

Types of NAT Gateways

  • Public NAT: A Public NAT gateway connects resources in a network to the internet.
  • Private NAT: A private NAT gateway connects two VPC networks in a region or cross-region.

The major difference between public and private NAT is private NAT gateway uses a private IP address that is used to map to internal private IP addresses of resources. This is helpful when an organization wants to restrict the use of IP addresses. Public NAT uses a registered Public IP address which is mainly used to connect to the internet or public network.

Steps to Configure Cloud NAT in GCP

Step 1: Firstly to configure cloud NAT we will setup a VM inside VPC network. Go to compute engine and select VM Instances and click on create instance .On create instance page specify options as below. specify name for instance and select region and zone . Select size for VM according to your requirement.

Create Instance

Step 2: Keep other options as default . Now click on Networking under advanced . Under networking specify your VPC network and subnet where you want to deploy VM.

Network Interfaces

Step 3: Now under IP address specify external IP address as none .

 IP address

Step 4: Leave other options as default and click on create . Once the VM is ready click on SSH .

Virtual machine

Step 5: Once logged in ping to any website using ping command . You should see you cant access internet. Close the SSH .

ping google

Step 6: To enable internet access we will now configure NAT gateway . Navigate to Cloud NAT on GCP and click on Get Started . On NAT gateway creation page specify name and select VPC network and subnet same as VM instance .

Create Cloud NAT Gateway

Step 7: For cloud router select create new . Give name to router and then click create.

Create Router

Step 8: After creating router leave other options as default and then click create. Once the NAT gateway is setup you should see running status .

Status checking Step 9: Now go back and connect to instance using SSH . Again ping to the same site as before . You should see you can access internet .

ping google

Thus we have configured public NAT gateway in GCP for outbound internet access .

Troubleshooting

  • If you cannot access the internet make sure you have configured NAT in correct region and for correct network.
  • Make sure your VM is in same subnet as NAT .
  • If you can access internet without NAT then you must have enabled external IP . So go back and disable it .

Conclusion

From this article we have seen what is Cloud NAT in GCP . We have also seen step by step process to configure Cloud NAT gateway in GCP.

FAQs on Cloud NAT

1. Why There Is Need Of NAT Gateway In GCP ?

NAT gateway is majorly used to aceses the internet from the private instance without using the public IP address

2. What Are Possible Use Cases To Use NAT ?

Here are the some Possible Use Cases:

  1. Outbound Internet Access for Private Subnets.
  2. Security and Isolation.
  3. Egress Control.
  4. P Address Conservation.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads