Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot connect to internet-facing NLB forwarding traffic to a private instance

I have configured a cloud with following configuration

  1. VPC with a public and private subnet in two availability zones. Public subnet has an internet gateway and private subnet has a NAT gateway configured
  2. An internet-facing Network Load Balancer allowing TCP traffic configured in both availability zones
  3. A target group to forward traffic from the load balancer
  4. An EC2 instance in private subnet configured with haproxy listening at port 80. It's security group is configured to accept TCP traffic at port 80 from both the subnets in which NLB is configured
  5. Added this instance to the target group, the status is healthy

When I try to hit the NLB DNS it is giving me 'Connection timed-out' error. I am expecting that when I hit NLB DNS it should forward me to the private instance. I have checked many AWS documents such as this link but still cannot find the resolution to this issue. Please feel free to ask for more information if this is not sufficient.

like image 868
bot Avatar asked Mar 14 '19 19:03

bot


People also ask

How do I connect to an EC2 instance in a private subnet?

To attach Amazon EC2 instances located in a private subnet, create public subnets in the same Availability Zones as the private subnets used by the backend instances. Then, associate the public subnets with your load balancer.

How does NLB forward traffic to nodes?

NLB enables each host to detect and receive incoming TCP/IP traffic. This traffic is received by all the hosts in cluster and NLB driver filter the traffic as per the Port Rules defined. NLB nodes don't communicate with each other for incoming traffic coming from client because NLB is enabled on all the nodes.

Can the instance in the private subnet be accessed directly from the internet?

The instances in the public subnet can send outbound traffic directly to the internet, whereas the instances in the private subnet can't. Instead, the instances in the private subnet can access the internet by using a network address translation (NAT) gateway that resides in the public subnet.

Can Network Load Balancer be internet facing?

An internet-facing load balancer routes requests from clients to targets over the internet. An internal load balancer routes requests to targets using private IP addresses. For IP address type, choose IPv4 or Dualstack. Use IPv4 if your clients use IPv4 addresses to communicate with the load balancer.


1 Answers

It's security group is configured to accept TCP traffic at port 80 from both the subnets in which NLB is configured

When targets are registered by instance-id, the security group for instances behind an Internet-facing NLB need to allow traffic from 0.0.0.0/0 -- or whatever range of public IP addresses need to access them through the balancer -- not just the subnets of the balancer (which are needed for health-checks).

If your target type is an instance, add a rule to your security group to allow traffic from your load balancer and clients to the target IP.

https://aws.amazon.com/premiumsupport/knowledge-center/security-group-load-balancer/

Unlike ALB and Classic balancers, NLB traffic has the source address of the external client when the targets are configured by instance-id, and this is the address the security group is matching against.

like image 162
Michael - sqlbot Avatar answered Oct 06 '22 16:10

Michael - sqlbot