Skip to content

Slow internet connection when using NAT Gateway

0

Context

I have a VPC in region eu-central-1 with 2 pairs of public-private subnets. I placed an EC2 instance (m5.2xlarge) in one of the private subnet and routed the public traffic of that subnet to a NAT Gateway placed in one of the public subnet.

Issue

The instance is able to reach the internet but the downlaod network speed is very low (~6 Mbit/s). If I move the instance from private to public subnet, therefore without passing through the NAT Gateway, the network speed jumps to ~1Gbit/s.

Attempts performed

  • change the availability zone of the subnets (tried eu-central-1a and eu-central-1b)
  • terminate and recreate the instance
2 Answers
1

The slow internet connection you're experiencing when using a NAT Gateway is not typical behavior for an m5.2xlarge instance, which should be capable of much higher network performance. However, there are several factors that could contribute to this issue:

  1. NAT Gateway capacity: While NAT Gateways can scale automatically, they do have limits on the number of simultaneous connections and bandwidth. If your application is generating a high volume of traffic or many concurrent connections, you might be hitting these limits.

  2. Route table configuration: Ensure that your route tables are correctly configured for both the private subnet (routing internet-bound traffic to the NAT Gateway) and the public subnet (routing internet-bound traffic to the Internet Gateway).

  3. Security groups and Network ACLs: Double-check that both inbound and outbound rules in your security groups and network ACLs are correctly configured to allow the necessary traffic.

  4. NAT Gateway status: Verify that your NAT Gateway is in an "Available" state and functioning correctly.

  5. Target resource limitations: The slow speed could be due to limitations on the target resource you're connecting to, rather than your AWS infrastructure.

  6. VPC DNS settings: Ensure that DNS hostnames and DNS resolution are enabled for your VPC, as these are necessary for proper name resolution.

To troubleshoot further:

  1. Use VPC Flow Logs to analyze traffic patterns and identify where communication might be breaking down.

  2. Check CloudWatch metrics for your NAT Gateway to gain insights into its performance and identify any potential issues.

  3. Test connections to various internet endpoints to determine if the slow speed is specific to certain destinations or a general issue.

  4. Consider creating additional NAT Gateways in different Availability Zones to distribute the load and improve redundancy.

If these steps don't resolve the issue, you may need to contact AWS support for further assistance, as there could be underlying network issues specific to your setup or region.

Sources
Instances within the private subnet are unable to access the internet using NAT gateway. | AWS re:Post
Server internet connection is slower than 2G networks | AWS re:Post
How to enable internet for EC2 using NAT Gateway? | AWS re:Post

answered 2 years ago

EXPERT

reviewed 2 years ago

0

In addition you may want to check the MTU of your instance ENI's. All current generation EC2 instances support an MTU size of 9001 bytes (Jumbo Frames). However, note that the MTU can change depending on the path taken by the packets: Although increasing the packet size (MTU) can help improve throughput, this must be done end- to-end to avoid packet fragmentation, which has the opposite effect - Could be causing the slower throughput.

NATGW has an MTU of 8500B which is less than your 9001B of current gen instances. This may causing packets to be dropped / or fragemented, reducing your affective throughput.

  1. Check MTU of the instances (e.g on linux instances) [root@ip-a.b.c.d bin]# ip a : enX0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc fq_codel state UP group default qlen 1000 link/ether 06:31:97:09:3f:c1 brd ff:ff:ff:ff:ff:ff altname eni-05de4c8b79763ced3 altname device-number-0.0

    <clip>
  2. run a tracepath to your destination or a public server you can test with. This will show you the PMTU at different points where your current MTU is too large. Some device along the path may respond with PMTUD (i.e IGW) This will then cause your instance to adjust the MTU accordingly (which is what you want). In some cases if you have disabled ICMP, you may not receive the PMTUD messages, and your device may continue sending larger packets which end up being fragmented.

i.e Public iperf server >> ping.online.net

root@ip-a.b.c.d bin]# tracepath ping.online.net 1?: [LOCALHOST] pmtu 9001 << Current Local MTU being implemented 1: ip-a.b.c.e 0.608ms << PMTUD is not implemented at NATGW 1: ip-a.b.c.f .compute.internal 0.806ms 2: ip-a.b.c.g.compute.internal 1.193ms pmtu 1500 << PMTUD is implemented at the IGW (this should cause your device to adjust the MTU, but worth checking) 2: 240.1.168.10 2.413ms asymm 8 3: 81.52.186.166 2.625ms asymm 10 4: 99.83.114.135 2.866ms asymm 9

  1. if your device is PMTU is higher than 1500, you can set it to 1500B

sudo ip link set dev eth0 mtu 1500

Hope this helps

AWS

answered 2 years ago

  • Thanks for sharing. Unfortunately this did not help. I have an EC2 instance that bakes an ECS cluster where pmtu is the same as the slow instance and the download speed is > 1 Gbit/s.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.