
Global Accelerator Now Preserves Client IP Even for NLBs with TLS Listeners, So I Tried It Out
This page has been translated by machine translation. View original
Introduction
On November 23, 2026, an AWS Global Accelerator update made it possible to add a Network Load Balancer (NLB) with a TLS listener as an endpoint that preserves the client IP address.
In this article, I add an NLB with a TLS listener to an accelerator and share the results of checking the source IP visible at the target and how the target's security group allows and denies traffic.
Test environment
- Region: Tokyo (ap-northeast-1)
- Global Accelerator API region: us-west-2
- AWS CLI: 2.42.1
- Target: t3.micro, Amazon Linux 2023, in a public subnet in apne1-az1
- NLB: public subnets in apne1-az1 and apne1-az2
Setup
NLB and target
The conditions under which Global Accelerator can preserve the client IP address at an NLB endpoint are as follows.
- The NLB has a security group attached
- The targets are in the same VPC as the NLB, and traffic flows directly from the NLB to the targets
- The NLB is not one that performs IPv4-to-IPv6 NAT for EC2 targets
The configuration this time consisted of an NLB with a security group and a target (IPv4) of target type instance in the same VPC. The target group attributes were left at their defaults: preserve_client_ip.enabled was true and proxy_protocol_v2.enabled was false.
Commands to create the prerequisite resources and the HTTP server on the target
On the target, I ran an HTTP server on 80/tcp that returns the source address of the received TCP connection. The contents of user-data.sh are as follows.
#!/bin/bash
# A small HTTP server (80/tcp) that returns the source address of the TCP connection on the target side as-is in the response
cat > /opt/whoami.py <<'EOF'
from http.server import BaseHTTPRequestHandler, HTTPServer
class H(BaseHTTPRequestHandler):
def do_GET(self):
body = f"remote_addr={self.client_address[0]}\n".encode()
self.send_response(200)
self.send_header("Content-Type", "text/plain")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, fmt, *args):
print(f"{self.client_address[0]} {fmt % args}", flush=True)
HTTPServer(("0.0.0.0", 80), H).serve_forever()
EOF
cat > /etc/systemd/system/whoami.service <<'EOF'
[Unit]
Description=whoami
After=network.target
[Service]
ExecStart=/usr/bin/python3 /opt/whoami.py
Restart=always
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now whoami
I ran the following commands in the same directory as user-data.sh. I defined the variables and imported a self-signed certificate into ACM. Then I created the security groups for the NLB and the target, the EC2 instance, and the target group, and registered the instance as a target.
Replace <...> with values from your environment. Creating the NLB and adding rules to the target's security group are explained later in the main text.
R=ap-northeast-1
VPC=<vpc-id> # Default VPC (with an Internet Gateway)
SUBNET_A=<subnet-id-az-a> # Two public subnets in different AZs
SUBNET_B=<subnet-id-az-b>
AMI=<al2023-ami-id> # SSM parameter /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64
MYIP=$(curl -s https://checkip.amazonaws.com)
openssl req -x509 -newkey rsa:2048 -nodes -keyout key.pem -out cert.pem -days 7 -subj "/CN=ga-tls-test.example.com"
CERT=$(aws acm import-certificate --region $R --certificate fileb://cert.pem --private-key fileb://key.pem \
--query CertificateArn --output text)
NLBSG=$(aws ec2 create-security-group --region $R --vpc-id $VPC --group-name nlb-sg --description nlb --query GroupId --output text)
TGTSG=$(aws ec2 create-security-group --region $R --vpc-id $VPC --group-name target-sg --description target --query GroupId --output text)
aws ec2 authorize-security-group-ingress --region $R --group-id $NLBSG --protocol tcp --port 443 --cidr 0.0.0.0/0
IID=$(aws ec2 run-instances --region $R --image-id $AMI --instance-type t3.micro --subnet-id $SUBNET_A \
--security-group-ids $TGTSG --associate-public-ip-address --user-data file://user-data.sh \
--metadata-options HttpTokens=required --query 'Instances[0].InstanceId' --output text)
TG_ARN=$(aws elbv2 create-target-group --region $R --name ga-nlb-tls-verify-tg --protocol TCP --port 80 \
--vpc-id $VPC --target-type instance --query 'TargetGroups[0].TargetGroupArn' --output text)
aws ec2 wait instance-running --region $R --instance-ids $IID
aws elbv2 register-targets --region $R --target-group-arn $TG_ARN --targets Id=$IID
To the target's security group, I added rules allowing 80/tcp from the /32 of my local global IP, and 80/tcp from the VPC CIDR for NLB health checks.
aws ec2 authorize-security-group-ingress --region $R --group-id $TGTSG --protocol tcp --port 80 --cidr ${MYIP}/32
aws ec2 authorize-security-group-ingress --region $R --group-id $TGTSG --protocol tcp --port 80 --cidr <vpc-cidr>
I created the NLB as internet-facing with the security group attached.
NLB_ARN=$(aws elbv2 create-load-balancer --region $R --name ga-nlb-tls-verify --type network --scheme internet-facing \
--subnets $SUBNET_A $SUBNET_B --security-groups $NLBSG --query 'LoadBalancers[0].LoadBalancerArn' --output text)
Next, I created a TLS listener that forwards to the target group.
aws elbv2 create-listener --region $R --load-balancer-arn $NLB_ARN --protocol TLS --port 443 \
--certificates CertificateArn=$CERT --ssl-policy ELBSecurityPolicy-TLS13-1-2-2021-06 \
--default-actions Type=forward,TargetGroupArn=$TG_ARN
Accelerator and endpoint
Commands to create the accelerator, listener, and endpoint group
ACC_ARN=$(aws globalaccelerator create-accelerator --region us-west-2 --name ga-nlb-tls-verify --ip-address-type IPV4 \
--enabled --query Accelerator.AcceleratorArn --output text)
LIS_ARN=$(aws globalaccelerator create-listener --region us-west-2 --accelerator-arn $ACC_ARN --protocol TCP \
--port-ranges FromPort=443,ToPort=443 --query Listener.ListenerArn --output text)
EG_ARN=$(aws globalaccelerator create-endpoint-group --region us-west-2 --listener-arn $LIS_ARN \
--endpoint-group-region $R --query EndpointGroup.EndpointGroupArn --output text)
In the CLI and API, to enable client IP address preservation for an NLB endpoint with a security group, you specify ClientIPPreservationEnabled=true when adding the endpoint. This time, I added the NLB with the TLS listener using add-endpoints.
# Wait until the NLB is active before running
aws elbv2 wait load-balancer-available --region $R --load-balancer-arns $NLB_ARN
aws globalaccelerator add-endpoints --region us-west-2 --endpoint-group-arn $EG_ARN \
--endpoint-configurations EndpointId=$NLB_ARN,ClientIPPreservationEnabled=true,Weight=128
The endpoint was added.
{
"EndpointDescriptions": [
{
"EndpointId": "arn:aws:elasticloadbalancing:ap-northeast-1:111122223333:loadbalancer/net/ga-nlb-tls-verify/1234567890abcdef",
"Weight": 128,
"ClientIPPreservationEnabled": true
}
],
"EndpointGroupArn": "arn:aws:globalaccelerator::111122223333:accelerator/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/listener/xxxxxxxx/endpoint-group/xxxxxxxxxxxx"
}
Checking the state before connecting
Connect after the accelerator's Status becomes DEPLOYED and the endpoint's HealthState becomes HEALTHY.
aws globalaccelerator describe-accelerator --region us-west-2 --accelerator-arn $ACC_ARN
aws globalaccelerator describe-endpoint-group --region us-west-2 --endpoint-group-arn $EG_ARN
Verification
Source IP visible at the target
I connected to the accelerator's static IP with curl and compared the source IP returned by the target with my local global IP. Because a self-signed certificate is used, certificate verification is skipped with -k.
GA_IP=$(aws globalaccelerator describe-accelerator --region us-west-2 --accelerator-arn $ACC_ARN \
--query 'Accelerator.IpSets[0].IpAddresses[0]' --output text)
curl -sk --max-time 15 -w 'http_code=%{http_code}\n' https://$GA_IP/
curl -s https://checkip.amazonaws.com
The first line is the target's response, the second line is the HTTP status, and the third line is my local global IP.
remote_addr=203.0.113.10
http_code=200
203.0.113.10
The IP that the target received as the source of the TCP connection matched my local global IP even without using Proxy Protocol.
Allow and deny in the security group
I removed the rule allowing the /32 of my local global IP from the target's security group.
aws ec2 revoke-security-group-ingress --region $R --group-id $TGTSG --protocol tcp --port 80 --cidr ${MYIP}/32
When I waited 5 seconds and tried the same connection, curl got no response and returned http_code=000.
I then restored the removed rule.
aws ec2 authorize-security-group-ingress --region $R --group-id $TGTSG --protocol tcp --port 80 --cidr ${MYIP}/32
When I connected 5 seconds later, http_code=200 and remote_addr=203.0.113.10 were returned, confirming that the target's security group allowed the /32 of my local global IP.
When preservation is disabled
I disabled preservation on the same NLB and compared the source seen by the target.
aws globalaccelerator update-endpoint-group --region us-west-2 --endpoint-group-arn $EG_ARN \
--endpoint-configurations EndpointId=$NLB_ARN,ClientIPPreservationEnabled=false,Weight=128
In the response, ClientIPPreservationEnabled became false.
With the target's security group allowing only the /32 of my local global IP and the VPC CIDR, curl got no response and returned http_code=000.
To check the source, I temporarily allowed 80/tcp from 0.0.0.0/0 in the target's security group. Then http_code=200 and remote_addr=13.248.98.206 were returned. In ip-ranges.json, this address belonged to 13.248.98.0/24 (region ap-northeast-1, service GLOBALACCELERATOR).
Summary
Now that Global Accelerator with client IP address preservation can use an NLB that terminates TLS, you can control access using the client IP address in the target's security group and in the application.
If not being able to see the client IP address when using an NLB with a TLS listener through Global Accelerator has been an issue for you, please give this update a try.
