Learn how to add NAT Gateway firewall rules for ports and protocols in Vultr.
NAT Gateway firewall rules control which traffic is permitted or denied through the gateway. Rules can restrict traffic by IP protocol, port number, and source subnet to enforce least-privilege access policies. Each firewall rule requires a corresponding port forwarding rule for the same port to exist before creation.
Follow this guide to create a NAT Gateway subscription firewall rule using the Vultr Customer Portal or API.
Navigate to Products, expand the Network drop-down and select VPC Networks.
Select your target VPC Network with NAT Gateway connectivity.
Scroll to the NAT Firewall section.
Click Add Firewall Rule.
A panel opens with the following configuration options:
0.0.0.0 to allow all IPv4 addresses).0 with 0.0.0.0 to allow all addresses, or specify a value like 24 for restricted subnets).443, 228000:8002Click Save Changes.
Send a GET request to the List VPCs endpoint to retrieve available VPCs.
$ curl "https://api.vultr.com/v2/vpcs" \
-X GET \
-H "Authorization: Bearer ${VULTR_API_KEY}"
The output displays all VPCs in your account. Note the id field for the target VPC.
Send a GET request to the List NAT Gateway subscriptions endpoint to retrieve the gateway ID. Replace VPC_ID with the ID from the previous step.
$ curl "https://api.vultr.com/v2/vpcs/VPC_ID/nat-gateway" \
-X GET \
-H "Authorization: Bearer ${VULTR_API_KEY}"
The output displays NAT Gateway subscriptions for the VPC. Note the id field for the target gateway.
Verify a port forwarding rule exists for the target port. Send a GET request to the List NAT Gateway Port Forwarding Rules endpoint. Replace VPC_ID and NAT_GATEWAY_ID with your values.
$ curl "https://api.vultr.com/v2/vpcs/VPC_ID/nat-gateway/NAT_GATEWAY_ID/global/port-forwarding-rules" \
-X GET \
-H "Authorization: Bearer ${VULTR_API_KEY}"
The output displays existing port forwarding rules. Verify a rule exists for your target port. If no rule exists, create one before proceeding.
Send a POST request to the Create NAT Gateway Firewall Rule endpoint. Replace VPC_ID and NAT_GATEWAY_ID with your values.
$ curl "https://api.vultr.com/v2/vpcs/VPC_ID/nat-gateway/NAT_GATEWAY_ID/global/firewall-rules" \
-X POST \
-H "Authorization: Bearer ${VULTR_API_KEY}" \
-H "Content-Type: application/json" \
--data '{
"protocol": "tcp",
"port": "443",
"subnet": "0.0.0.0",
"subnet_size": 0,
"notes": "Allow HTTPS traffic"
}'
Replace the field values as follows:
protocol: Specify tcp or udpport: Specify the destination port or port range."443", "22""8000:8002"subnet: Specify the source subnet in CIDR notation (use 0.0.0.0 to allow all IPv4 addresses)subnet_size: Enter the subnet mask size (use 0 with 0.0.0.0 to allow all addresses, or specify a value like 24 for restricted subnets)notes: Provide a description for the ruleThe output displays the created firewall rule with an automatically assigned id and action field set to accept.