Reputation: 6531
Problem:
When I am on the instance 10.141.80.140 and curl the DNS of NLB
I get no response.
I expect the NLB to redirect to 10.141.80.140 but it doesnt happen.
The NLB DNS only doesnt redirect, when I am on the 10.141.80.140 - the redirection works from other instances in the same subnet
Details:
Question:
Is there something, what prevents NLB to resolve the request of an instance,
which would route back to the instance, within the NLB listeners target group?
Upvotes: 6
Views: 1840
Reputation: 2589
Added to the above answer ─ yes, the problem occurs if you sent request from the same instance which is added as a backend for NLB. In short,
Network Load Balancers preserve the source IP, so both the source and destination of the arriving packet are the private IP address of the target. Then, the host operating system sees the packet as not valid so it doesn't send response traffic, and the connection fails.
More details here:-
If an instance must send requests to a load balancer that it's registered with, do one of the following:
Disable client IP preservation.[2]
Ensure that containers that must communicate, are on different container instances.
Upvotes: 2
Reputation: 6531
that is a well-know behavior that I am going to be glad to explain. Network Load Balancer introduced the source address preservation feature - the original IP addresses and source ports for the incoming connections remains unmodified. When the target answers a request, the VPC internals capture this packet and forwards it to the NLB, which will forward it to its destination.
This behavior has a side effect: when the OS kernel detects that the egress packet has as the destination address one of the local addresses, it will forward this packet directly to the application.
For example, given the following components:
The backend instance has the address 10.0.0.55 and has a web server listening on port 8080. It has a security group that allows all the incoming local traffic.
If the instance tries to establish a communication with the NLB; the flow of the communication would be the following:
This will not happen with a public NLB, as the instance will need to do NAT in the VPC to use its public IP address to send the request to the NLB. The kernel will not internally forward the packet.
Finally, a possible workaround is registering the backends as per their IP address, not by their Instance ID; with this method, the traffic forwarded by the NLB will contain the NLB internal IP as the source IP, disabling the "source address preservation" feature. Unfortunately, if you are launching instances with an AutoScaling Group, it will only be able to register the launched instances by its ID. In case of ECS tasks, configuring the network as "awsvpc" forces the NLB to register each target by its IP.
Upvotes: 9