Skip to content

How do I troubleshoot Amazon EC2 security group connection tracking issues in Amazon VPC?

6 minute read
0

I want to troubleshoot connection tracking issues for my Amazon Elastic Compute Cloud (Amazon EC2) security group in Amazon Virtual Private Cloud (VPC).

Short Description

Issues related to Amazon EC2 security group connection tracking cause connection timeouts, inconsistent connectivity, and packet drops.

Resolution

Check whether your security group tracks your connection. If your security group tracks your connection, then troubleshoot issues with new or established connections.

Prerequisite: Use the AWSSupport-EnableVPCFlowlogs runbook to activate Amazon VPC Flow Logs. It's a best practice to activate custom Amazon VPC Flow Logs that capture the tcp-flags field.

Check if your connection is tracked

Amazon EC2 security groups don't track all flows of traffic. For information on traffic that security groups don't track, see Untracked connections.

Verify that security groups track the connection that experiences connectivity problems. Security groups track Internet Control Message Protocol (IMCP) traffic and connections that you reference in your inbound and outbound rules. Check that your connection isn't automatically tracked regardless of security group rules.

Troubleshoot issues with new connections

Connection tracking uses memory and compute resources to define the maximum number of connections that your Amazon EC2 instance can maintain. If your instance exceeds its connection tracking allowance, then you experience packet drops and can’t establish new connections.

Monitor the following Amazon Elastic Network Adapter (ENA) driver metrics:

  • Use the conntrack_allowance_available metric to monitor the number of tracked connections that you can use before your instance exceeds its allowance.
  • Use the conntrack_allowance_exceeded metric to monitor if your instance exceeds its allowance.

Security groups automatically track connections that pass through Elastic Load Balancing (ELB) Gateway Load Balancers, Network Load Balancers, or NAT Gateways. These resources have different TCP established timeout and UDP timeout values differ from the idle connection tracking timeout attributes for network interfaces and impact your instance’s connection tracking allowance usage. For more information, see the Scenario #1: TCP connections through AWS Services (NLB) section of Introducing configurable idle timeout for connection tracking.

If your instance doesn’t support ENA driver metrics, then complete the following steps:

  1. Retrieve the flow logs for your instance.
    Note: Amazon VPC Flow Logs doesn't capture packets that are dropped because an instance exceeds its connection tracking allowance.
  2. Use Wireshark or tcpdump to capture the network packets for your instance. For Wireshark, filter by protocol, port, or IP address. For tcpdump, run the following command:
    sudo tcpdump -i eth0 host example-ip and port example-port
    Note: Replace example-ip with the destination IP address or host name. Replace example-port with your port.
  3. Review your packet capture for traffic that exits on your elastic network interface. Then, in your flow logs, look for the connection that you discovered in your packet capture. If your flow logs don’t record that connection, then that indicates your instance might exceed its allowance.

If your instance exceeds its allowance, then take the following actions:

If your instance doesn't exceed its connection tracking allowance, then troubleshoot the connection tracking allowance for your operating system (OS).

To troubleshoot OS-level connection tracking allowances, check that connection tracking is active for your Linux kernel. If connection tracking is active, then complete the following steps:

  1. Run one of the following commands to review the total number of connections that your security group tracks:

    cat /proc/sys/net/netfilter/nf_conntrack_count

    -or-

    conntrack -L
  2. Run the following command to clear the entries from your connection tracking table:

    conntrack --flush
  3. Run the following command to check your connection tracking allowance value of your operating system (OS):

    cat /proc/sys/net/nf_conntrack_max

Note: Your OS-level connection tracking allowance isn't the same as your Amazon VPC security group's connection tracking allowance.

If your number of tracked connections matches your OS-level connection tracking allowance, then consider increasing your OS-level connection tracking allowance.

Troubleshoot issues with established connections

Troubleshoot connection issues caused by security group rule changes

If you modify a security group rule to begin tracking an established connection that it doesn't track, then your security group immediately disrupts the connection.

When you change your security group rules, adhere to the following best practices:

  • Temporarily allow all traffic in your security group rules to isolate misconfiguration.
  • Incrementally reapply restrictive rules, testing after each change. Be sure to test after each change and verify that your rules allow established connections to complete.

Troubleshoot idle connections that exceed timeouts

When a tracked connection receives a packet outside its idle timeout, your security group re-evaluates the packet against its inbound or outbound rules. If the security group rules don't allow the packet, then you receive REJECT entries for established connections in your flow logs.

In the following example flow logs, the established tracked connection receives a REJECT after multiple ACCEPT entries. The example flow logs indicate that the connection receives a packet outside of its idle timeout:

2 033605635 eni-90af8 192.0.2.10 192.0.2.20 443 51506 6 7 1285 1517386884 1517387004 ACCEPT OK  
2 033605635 eni-90af8 192.0.2.20 192.0.2.10 51506 443 6 15 3670 1517386884 1517387064 ACCEPT OK  
2 033605635 eni-90af8 192.0.2.10 192.0.2.20 443 51506 6 6 240 1517387004 1517387064 REJECT OK

Note: Amazon VPC Flow Logs don't capture real-time interface logs.

To check if you receive the packets outside of the predefined idle timeouts, complete the following steps:

  1. Retrieve the flow logs for your instance and identify REJECT entries.
  2. Use Wireshark or tcpdump to capture the network packets for your instance in both directions.
  3. In your flow logs, identify entries with REJECT statuses.
  4. In your packet capture, identify the connections that correspond with the REJECT entries that you identified in step 3.
  5. To confirm if the packets arrive outside the idle timeout values, calculate the time between when the packets are sent and received. For instructions, see How to Graph TCP Delta Times in Wireshark on the Fir3 website.

If your packet arrives outside of your idle timeout values, then take the following actions:

  • Configure TCP keepalive at the application or OS level. For instructions, see the TCP Keepalive section of Implementing long-running TCP Connections Within VPC Networking.
  • Adjust your instance's idle tracking timeout attributes.
  • Configure your security group to explicitly allow response traffic.
AWS OFFICIALUpdated a year ago