Lesson 3 of 6 Hybrid DNS and Network Security

Controlling Outbound Internet Traffic

This lesson explains how egress design decides where outbound traffic leaves AWS and what it may reach, since every workload that can reach any internet destination is a potential path for exfiltration or command-and-control traffic.

Learning outcomes

After completing this lesson, you will be able to:

  • Choose between centralised and distributed egress.
  • Explain how domain lists and DNS Firewall restrict destinations.
  • Explain how VPC endpoints remove the need for internet egress.
  • Describe how VPC Block Public Access blocks internet access at scale.

Egress designs

Internet egress can be centralised or distributed. In centralised egress, NAT gateways sit in a shared egress VPC behind the transit gateway, and every VPC sends internet traffic there. Fewer NAT gateways are needed, and filtering and logging happen in one place. On the other hand, every byte pays transit gateway data processing charges, and the egress VPC is a shared failure domain. In distributed egress, each VPC has its own NAT gateways. A problem affects only one VPC and there are no transit gateway charges, but there are more NAT gateways to pay for, and any filtering must be repeated in every VPC. The following table summarises the trade-offs.

DesignAdvantagesDisadvantages
Centralised egress (NAT gateways in a shared egress VPC behind the transit gateway)Fewer NAT gateways; one place for filtering and loggingTransit gateway data processing charges; shared failure domain
Distributed egress (NAT gateways in each VPC)Smaller blast radius; no transit gateway chargesMore NAT gateways; filtering repeated in every VPC

Restricting destinations

Routing decides where egress leaves; filtering decides what it may reach, and several layers combine. Network Firewall domain lists allow only approved domains, such as package repositories and partner APIs, by matching the TLS Server Name Indication and HTTP host header of each connection. Route 53 Resolver DNS Firewall blocks lookups of unapproved or malicious domains before a connection is even attempted.

Security groups and network ACLs limit ports and, with managed prefix lists, destination ranges, which suits destinations known by address. Where outbound traffic must be authenticated per user or its content inspected, an explicit proxy fleet behind a load balancer remains an option, at the cost of operating it. Combining DNS filtering with connection filtering matters, because malware can connect directly to IP addresses without any DNS lookup.

Removing the need for internet egress

The safest and often cheapest egress is none at all. Much outbound traffic from private workloads goes to AWS services, and gateway endpoints for S3 and DynamoDB, which are free, together with interface endpoints for other services, keep that traffic off the internet path entirely and reduce NAT gateway processing charges. PrivateLink endpoints offered by SaaS providers replace internet connections to those providers in the same way.

VPC endpoint policies then restrict which resources can be reached through each endpoint, for example only the organisation's own buckets, which supports the resource perimeter of a data perimeter design. A workload whose dependencies are all reachable through endpoints can run in subnets with no route to the internet at all.

Blocking internet access at scale

VPC Block Public Access blocks traffic through internet gateways and egress-only internet gateways for a whole Region, with exclusions for the VPCs or subnets that should keep access, such as a central egress VPC. A declarative policy in AWS Organizations enforces the setting across every account.

Worked example

Allowing internet egress only to approved domains

Workloads in private subnets across 30 VPCs need to download packages and call a few SaaS APIs, and nothing else on the internet. The company centralises egress: NAT gateways in a shared egress VPC behind the transit gateway, with Network Firewall in front of them. Egress is limited to approved domains with a stateful rule group:

aws network-firewall create-rule-group --rule-group-name egress-allow --type STATEFUL --capacity 100 \
  --rule-group '{"RulesSource":{"RulesSourceList":{
     "Targets":[".amazonaws.com",".github.com","pypi.org"],
     "TargetTypes":["TLS_SNI","HTTP_HOST"],"GeneratedRulesType":"ALLOWLIST"}}}'

Because the rule group matches the TLS server name and HTTP host header, it allows only the listed domains and drops other HTTP and HTTPS flows. Several further measures complete the design. S3 and DynamoDB gateway endpoints in every VPC take the largest flows off the egress path at no cost. DNS Firewall blocks lookups of known malicious domains before any connection is attempted. VPC Block Public Access, enforced by a declarative policy with an exclusion for the egress VPC, stops any team attaching its own internet gateway and bypassing the controls.

Check yourself

How do VPC endpoints reduce the need for internet egress?

Show answer

Traffic to AWS services stays on the AWS network through gateway or interface endpoints, so private subnets reach those services without a NAT gateway or an internet route.

Exam Tips

Remember for the exam

  • For fewer NAT gateways and central filtering, use a centralised egress VPC.
  • For a smaller blast radius and no transit gateway charges, use distributed NAT gateways.
  • To allow outbound traffic only to approved domains, use Network Firewall domain lists and DNS Firewall.
  • VPC endpoints remove AWS API traffic from the internet egress path.
  • To block internet access across accounts with exceptions, use VPC Block Public Access with a declarative policy.