I Tried Associating a NAT Gateway with AWS Network Firewall and Using an Explicit Proxy

I Tried Associating a NAT Gateway with AWS Network Firewall and Using an Explicit Proxy

In the Tokyo Region, I set up AWS Network Firewall as an explicit proxy with a NAT Gateway and confirmed that curl traffic via the proxy can be allowed or denied per domain with DNS and TLS SNI rules. The source IP was the NAT Gateway's Elastic IP.
2026.11.24

This page has been translated by machine translation. View original

Introduction

On November 19, 2026, AWS Network Firewall added support for the explicit proxy feature and NAT Gateway association.

https://aws.amazon.com/jp/about-aws/whats-new/2026/11/network-firewall-proxy-nat-gateway/

In this article, I associate a NAT Gateway with AWS Network Firewall, configure it as an explicit proxy, and verify that traffic from curl using the proxy is allowed or denied, as well as the source IP seen from the destination.

Test Environment

  • Region: Tokyo (ap-northeast-1)
  • AZ: ap-northeast-1a
  • AWS CLI: 2.42.1
  • Firewall policy: Next Generation policy
  • Client: t3.micro (Amazon Linux 2023, no public IP)
  • VPC CIDR: 10.100.0.0/16
  • VPC DNS hostnames: enabled

Creating the NAT/Proxy firewall

Subnet configuration

I created the following three subnets in ap-northeast-1a. Network Firewall creates the NAT Gateway in the NAT subnet and the firewall endpoint in the firewall endpoint subnet.

Purpose CIDR
For NAT 10.100.0.0/24
For firewall endpoint 10.100.1.0/24
For client 10.100.2.0/24

I enabled the VPC DNS hostnames with the following command.

aws ec2 modify-vpc-attribute --vpc-id <VPC_ID> --enable-dns-hostnames

Rules and policy

The policy approach is as follows.

  • Default action: drop
  • Allow: only checkip.amazonaws.com
  • Explicit drop: dev.classmethod.jp (DNS rule)

Save the following 8 lines as rules.txt. sid 1 to 5 are carrier rules for delivering traffic to the DNS and TLS SNI rules. sid 10 is the drop for dev.classmethod.jp, and sid 11 and sid 21 are the allows for checkip.amazonaws.com (DNS and TLS SNI).

accept:hook udp:all any any -> any 53 (sid:1;)
accept:hook udp:all any 53 -> any any (sid:2;)
accept:hook tcp:all any any -> any 443 (tcp.session:setup,established; app-layer-protocol:unknown|tls; sid:3;)
accept:hook tcp:all any 443 -> any any (tcp.session:setup,established; app-layer-protocol:unknown|tls; sid:4;)
accept:hook dns:request_started any any -> any 53 (sid:5;)
drop:flow dns:request_complete any any -> any 53 (dns.query; content:"dev.classmethod.jp"; endswith; nocase; msg:"deny dns dev.classmethod.jp"; alert; sid:10;)
accept:flow dns:request_complete any any -> any 53 (dns.query; content:"checkip.amazonaws.com"; startswith; endswith; nocase; sid:11;)
accept:flow tls:<client_hello any any -> any 443 (tls.sni; content:"checkip.amazonaws.com"; startswith; endswith; nocase; sid:21;)

Convert rules.txt to JSON with jq and create the rule group.

jq -Rs '{RulesSource:{RulesString:.}}' rules.txt > rule-group-firewall.json

aws network-firewall create-rule-group \
  --rule-group-name nfw-proxy-verify-fw-rules \
  --type FIREWALL \
  --capacity 200 \
  --firewall-rule-group file://rule-group-firewall.json \
  --query RuleGroupResponse.RuleGroupArn --output json

Specify the ARN of the rule group in the response as the ResourceArn in the following firewall-policy-v2.json.

{
  "FirewallRuleGroupEntries": [ { "Priority": 100, "ResourceArn": "<RULE_GROUP_ARN>" } ],
  "IpsRuleGroupEntries": [],
  "PolicyMode": "ENFORCE",
  "FirewallDefaultAction": "DROP",
  "StatefulEngineOptions": { "StreamExceptionPolicy": "REJECT" }
}
aws network-firewall create-firewall-policy-v2 \
  --firewall-policy-v2-name nfw-proxy-verify-policy \
  --firewall-policy-v2 file://firewall-policy-v2.json

FirewallPolicyV2Response.FirewallPolicyV2Arn in the response is the policy ARN to pass to the following create-firewall.

Creating the firewall

Allocate an Elastic IP to attach to the NAT Gateway, and then create the firewall.

aws ec2 allocate-address --domain vpc

The arguments of create-firewall are as follows.

  • --nat-gateway-create-mappings: Specify the NAT subnet, the Elastic IP allocation ID, and a private IP in the NAT subnet (10.100.0.10). Network Firewall creates the NAT Gateway with these settings.
  • --vpc-endpoint: Specify the VPC and the subnet for the firewall endpoint.
aws network-firewall create-firewall \
  --firewall-name nfw-proxy-verify \
  --firewall-policy-arn <FIREWALL_POLICY_ARN> \
  --nat-gateway-create-mappings SubnetId=<NAT_SUBNET_ID>\,AllocationIds=<ALLOCATION_ID>\,PrivateIps=10.100.0.10 \
  --vpc-endpoint VpcId=<VPC_ID>\,SubnetMappings=\[\{SubnetId=<FIREWALL_ENDPOINT_SUBNET_ID>\,IPAddressType=IPV4\}\]

If you do not pass --proxy-settings, the proxy listener ports are 3128 for HTTP and 8443 for HTTPS.

It took about 6.5 minutes from running create-firewall until the Status became READY. Once it is READY, check the NAT Gateway association with describe-firewall.

aws network-firewall describe-firewall --firewall-name nfw-proxy-verify
{
    "FirewallStatus": {
        "Status": "READY",
        "ConfigurationSyncStateSummary": "IN_SYNC",
        "SyncStates": {
            "ap-northeast-1a": {
                "Attachment": {
                    "SubnetId": "subnet-0123456789abcdef0",
                    "EndpointId": "vpce-0123456789abcdef0",
                    "Status": "READY",
                    "DnsName": "proxy-0123456789abcdef0.nfw.ap-northeast-1.amazonaws.com"
                },
                "NatGatewayAttachments": [
                    {
                        "NatGatewayId": "nat-0123456789abcdef0",
                        "Status": "READY"
                    }
                ]
            }
        }
    }
}

With describe-nat-gateways, you can check the NAT Gateway association and IP address.

aws ec2 describe-nat-gateways --filter Name=vpc-id\,Values=<VPC_ID>
{
    "NatGateways": [
        {
            "NatGatewayAddresses": [
                {
                    "AllocationId": "eipalloc-0123456789abcdef0",
                    "PrivateIp": "10.100.0.10",
                    "PublicIp": "203.0.113.10",
                    "IsPrimary": true,
                    "Status": "succeeded"
                }
            ],
            "NatGatewayId": "nat-0123456789abcdef0",
            "State": "available",
            "ConnectivityType": "public",
            "AttachedAppliances": [
                {
                    "Type": "network-firewall",
                    "ApplianceArn": "arn:aws:network-firewall:ap-northeast-1:123456789012:firewall/nfw-proxy-verify",
                    "AttachmentState": "attached"
                }
            ]
        }
    ]
}
Alert log settings

To check which rule blocked the traffic, I output ALERT logs to CloudWatch Logs.

aws logs create-log-group --log-group-name /nfw-proxy-verify/alert

Save logging-alert.json with the following content.

{"LogDestinationConfigs":[{"LogType":"ALERT","LogDestinationType":"CloudWatchLogs","LogDestination":{"logGroup":"/nfw-proxy-verify/alert"}}]}
aws network-firewall update-logging-configuration \
  --firewall-name nfw-proxy-verify \
  --logging-configuration file://logging-alert.json

Connecting via the proxy

The proxy hostname is in FirewallStatus.SyncStates.<AZ>.Attachment.DnsName of describe-firewall. On the client, specify this hostname and the port of each listener in environment variables.

export http_proxy=http://<PROXY_HOSTNAME>:3128
export https_proxy=https://<PROXY_HOSTNAME>:8443
export no_proxy=169.254.169.254,localhost

I connected to an allowed host, a denied host, and a host with no allow rule as follows.

curl -sS -m 15 https://checkip.amazonaws.com
curl -sS -m 40 -o /dev/null -w 'http_code=%{http_code}\n' https://dev.classmethod.jp/
curl -sS -m 40 -o /dev/null -w 'http_code=%{http_code}\n' https://aws.amazon.com/

Even when specifying the HTTPS listener, no additional CA specification was needed for curl. Even when I pointed https_proxy at the HTTP listener (http://<PROXY_HOSTNAME>:3128), checkip.amazonaws.com returned HTTP 200.

Verification results

Allow and deny

"Alert" in the table is the app_proto and sid that appeared in the alert log.

Destination Client result Alert
checkip.amazonaws.com HTTP 200, body is 203.0.113.10 None
dev.classmethod.jp CONNECT tunnel failed, response 502 (after about 30 seconds) dns, sid 10 (deny dns dev.classmethod.jp)
aws.amazon.com (no allow rule) CONNECT tunnel failed, response 502 (after about 30 seconds) dns, sid 2201001 (SURICATA FW default app policy)

dev.classmethod.jp was blocked by the DNS rule (sid 10), and aws.amazon.com, which has no allow rule, was blocked by the policy's default drop.

Source IP seen from the destination

The IP returned by checkip.amazonaws.com matched the PublicIp (203.0.113.10) from describe-nat-gateways.

Summary

The Network Firewall explicit proxy and NAT Gateway association are now available in the Tokyo Region as well.

The Network Firewall explicit proxy, announced as a public preview in November 2025, can be used when you want to restrict the destinations of traffic from EC2 instances in a VPC to only specified domains, such as Windows Update or package distribution repositories.

https://aws.amazon.com/jp/about-aws/whats-new/2025/11/aws-network-firewall-proxy-preview/

If you have been using your own forward proxy or similar to restrict destinations, give this update a try.

Share this article

AWSのお困り事はクラスメソッドへ

Related articles