Google’s Cloud NAT gateway

Thanks to Yuvraaj at crave.io for the following

Google launched something called Cloud NAT Gateway that charges for bandwidth to do NAT. It makes it more expensive to run than going with external IP (at least in the low volumes that I do). I found this blog entry by Yuvraaj at Crave.io that allows you to enable NAT in a few steps. I’ve documented the commands below so I can refer to them in the future if I need them and in case the crave.io blog entry is no longer available or I can’t find it for some reason.

Create or edit this file/script that runs everytime the machine is booted

/etc/rc.local
#!/bin/bash

set -x

# Turn on IP forwarding
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
# Turn on the route
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Setup Route in GCP Routing table

gcloud compute routes create no-ip-internet-route --network default --destination-range 0.0.0.0/0 --next-hop-instance nat-gateway --next-hop-instance-zone us-west1-b --tags no-ip --priority 800

Setup networking tags for VMs that need this

gcloud compute instances add-tags <existing-instance> --tags no-ip

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.