Cloud NAT rules  |  Google Cloud (2024)

The NAT rules feature lets you create access rules that define howCloud NAT is used to connect to the internet. NAT rules support sourceNAT based on destination address.

When you configure a NAT gateway without NAT rules, the VMs using that NAT gatewayuse the same set of NAT IP addresses to reach all internet addresses. If youneed more control over packets that pass through Cloud NAT, you canadd NAT rules. A NAT rule defines a match condition and a corresponding action.After you specify NAT rules, each packet is matched with each NAT rule. If apacket matches the condition set in a rule, then the action corresponding tothat match occurs.

Cloud NAT rule configuration example

The following example illustrates how to use NAT rules when your destinationallows access from only a few IP addresses. We recommend that the traffic tosuch destinations from your Google Cloud VMs in private subnets aresource NAT-translated with only the permitted IP addresses. We recommend thatyou do not use these IP addresses for other destinations.

Consider the following requirements for VMs in Subnet-1 (10.10.10.0/24),which is in Region A of the VPC network test:

  • The VMs must use NAT IP address 203.0.113.20 to send traffic to destination198.51.100.20/30.
  • The VMs must use NAT IP address 203.0.113.30 to send traffic to destination198.51.100.30 or 198.51.100.31.
  • The VMs must use NAT IP address 203.0.113.40 to send traffic to any otherinternet destination.

This VPC network also contains two additional subnets in thesame region. These VMs must use NAT IP address 203.0.113.10 to send trafficto any destination.

You can use NAT rules for this example, but you need two NAT gateways becauseSubnet-1 (10.10.10.0/24) has NAT rules that are different from the othersubnets. To create this configuration, follow these steps:

  1. Create a gateway called Cloud NAT Gateway 1 for Subnet-1 with NAT IPaddress 203.0.113.40 and add the following rules:
    1. NAT rule 1 in Cloud NAT Gateway 1: When the destination is198.51.100.20/30, use source NAT with 203.0.113.20.
    2. NAT rule 2 in Cloud NAT Gateway 1: When the destination is198.51.100.30 or 198.51.100.31, use source NAT with 203.0.113.30.
  2. Create a gateway called Cloud NAT Gateway 2 for the region's other subnetsand assign the NAT IP address as 203.0.113.10. No NAT rules are needed inthis step.

NAT rules specifications

Before working with NAT rules, note the following specifications:

  • A rule number uniquely identifies a NAT rule. No two rules can have the samerule number.
  • Each NAT configuration has a default rule:
    • The default rule is applied if no other NAT rule matches in the same NATconfiguration.
    • The rule number of the default rule is 65001.
    • The destination IP CIDR range of the default rule is 0.0.0.0/0.
  • Cloud NAT rules are supported only when the value of the NAT IP allocateoption is MANUAL_ONLY.
  • All IP addresses configured in a given rule must be of the same tier.

    You cannot use a mix of Premium Tier and Standard Tier IP addresses withinthe same rule (including the default rule).

  • Destination IP CIDR ranges in the match condition must not overlap across NATrules. There can be at most one rule that can match any given packet.

    You cannot create a NAT rule with a destination IP CIDR range of 0.0.0.0/0,because that range is used in the default rule.

  • NAT IP addresses across NAT rules must not overlap.

  • A rule must either have a non-empty Active or non-emptyDrain IP address.If the rule has an empty Active IP address, new connections thatmatch the NAT rule are dropped.

  • NAT rules cannot be added to a NAT gateway that hasEndpoint-Independent Mapping enabled. Youcannot enable Endpoint-Independent Mapping on a NAT gateway thathas NAT rules in it.

In addition, all VMs get ports assigned to them from the value for minimum portsper VM for each Cloud NAT rule. If the ports allocated to a VM from aNAT rule are exhausted, new connections that match the NAT rule are dropped.

For example, if you configure 4,096 ports per VM and have 16 VMs and 2 NAT rules(rule1 with 1 IP address and rule2 with 2 IP addresses), alongside the default rule(default) with 2 IP addresses, all 16 VMs would get 4,096 ports in each bundleof NAT rules. In this example, there are no issues in default or rule2 forall their VMs, but rule1 isn't able to allocate ports for all its VMs.Therefore, traffic from VMs that needs to go through rule1 might be droppedand show signs of being out of resources because the traffic does not use thedefault rule.

Rule expression language

NAT rules are written usingCommon Expression Language syntax.

An expression requires two components:

  • Attributes that can be inspected in rule expressions.
  • Operations that can be performed on the attributes as part of an expression.

For example, the following expression uses the attributes destination.ip and198.51.100.0/24 in the operation inIpRange(). In this case, the expressionreturns true if destination.ip is within the 198.51.100.0/24 IP address range.

inIpRange(destination.ip, '198.51.100.0/24')

NAT rules support only the following attributes and operations:

Attributes

Attributes represent information from an outgoing packet, such as thedestination IP address.

Attribute name Description
destination.ip Destination IP address of the packet

Operations

The following reference describes the operators that you can use with attributesto define rule expressions.

Operation Description
inIpRange(string, string) -> bool inIpRange(X, Y) returns true if IP CIDR range Y contains the IP address X.
|| Logical operator. x || y returns true if x or y is true.
== Equals operator. x == y returns true if x is equal to y.

Example expressions

Match traffic with destination IP address 198.51.100.20.

"destination.ip == '198.51.100.20'"

Match traffic with destination IP address 198.51.100.10/30 or 198.51.100.20.

"inIpRange(destination.ip, '198.51.100.10/30') || destination.ip == '198.51.100.20'"

What's next

  • Learn to configure NAT rules.
Cloud NAT rules  |  Google Cloud (2024)
Top Articles
Co to jest potwierdzenie tożsamości przez bank i jak to działa w praktyce?
Change the scale of the horizontal (category) axis in a chart
Duralast Gold Cv Axle
Unit 30 Quiz: Idioms And Pronunciation
Pga Scores Cbs
Best Transmission Service Margate
Mohawkind Docagent
Crazybowie_15 tit*
Best Restaurants In Seaside Heights Nj
Smokeland West Warwick
Tight Tiny Teen Scouts 5
Azeroth Pilot Reloaded - Addons - World of Warcraft
The Rise of Breckie Hill: How She Became a Social Media Star | Entertainment
More Apt To Complain Crossword
Craigslist Alabama Montgomery
Scholarships | New Mexico State University
A rough Sunday for some of the NFL's best teams in 2023 led to the three biggest upsets: Analysis - NFL
Louisiana Sportsman Classifieds Guns
Extra Virgin Coconut Oil Walmart
Gem City Surgeons Miami Valley South
Zack Fairhurst Snapchat
Aris Rachevsky Harvard
Libinick
Dover Nh Power Outage
Teacup Yorkie For Sale Up To $400 In South Carolina
Heart Ring Worth Aj
Red8 Data Entry Job
Ewg Eucerin
How To Make Infinity On Calculator
Grandstand 13 Fenway
Rocksteady Steakhouse Menu
Southern Democrat vs. MAGA Republican: Why NC governor race is a defining contest for 2024
Glossytightsglamour
Timothy Kremchek Net Worth
Agematch Com Member Login
Naya Padkar Newspaper Today
Gold Nugget at the Golden Nugget
9 oplossingen voor het laptoptouchpad dat niet werkt in Windows - TWCB (NL)
Fwpd Activity Log
Torrid Rn Number Lookup
Sams Gas Price Sanford Fl
Natasha Tosini Bikini
Wordle Feb 27 Mashable
Tinfoil Unable To Start Software 2022
Advance Auto.parts Near Me
Iman Fashion Clearance
Contico Tuff Box Replacement Locks
855-539-4712
Craigslist Chautauqua Ny
Glowforge Forum
The Ultimate Guide To 5 Movierulz. Com: Exploring The World Of Online Movies
Bellin Employee Portal
Latest Posts
Article information

Author: Errol Quitzon

Last Updated:

Views: 6201

Rating: 4.9 / 5 (79 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Errol Quitzon

Birthday: 1993-04-02

Address: 70604 Haley Lane, Port Weldonside, TN 99233-0942

Phone: +9665282866296

Job: Product Retail Agent

Hobby: Computer programming, Horseback riding, Hooping, Dance, Ice skating, Backpacking, Rafting

Introduction: My name is Errol Quitzon, I am a fair, cute, fancy, clean, attractive, sparkling, kind person who loves writing and wants to share my knowledge and understanding with you.