---
title: "NLB targets unhealthy after a deploy: security group or application? | Proofline"
description: "Compare the new tasks' inbound rules with the address the Network Load Balancer sends from, then check whether the application answered the health check."
url: https://proofline.sh/learn/nlb-targets-unhealthy-security-group/
---

[Learning center](/learn/)

# NLB targets unhealthy after a deploy: security group or application?

Compare the new tasks' inbound rules with the address the Network Load Balancer sends from, then check whether the application answered the health check. The load balancer's security groups and the target group's client IP preservation setting decide which source the rules must admit.

Network outages The Proofline team November 22, 2026 8 min read

## The signature and its nearby causes

A service behind a Network Load Balancer is redeployed. `describe-target-health` shows the new targets `unhealthy` while the old ones stay `healthy`, or every target is healthy but clients time out against the new tasks. Three causes sit close together:

-   **The new tasks' security group drops the health checks.** The deployment attached a new or edited security group that does not admit the load balancer on the health check port. Targets go unhealthy.
-   **The security group admits health checks but drops client traffic.** With client IP preservation on and no load balancer security group, targets see the client's address, and a rule that only admits the VPC range passes health checks while clients fail.
-   **The application fails the check.** The rules admit the traffic, and the process is not listening on the port or answers an HTTP check with the wrong status.

The first two are network fixes in the deployment's configuration. The third belongs to the release. Reason codes for Application Load Balancer targets are a separate question, and other signatures are in [the signature table](/learn/aws-deployment-failure-signatures/).

## Know which source the target sees

A Network Load Balancer can be created with or without security groups, and groups can only be changed later if at least one was set at creation. Client IP preservation is a target group attribute. It defaults to disabled for target type `ip` with protocol TCP or TLS, and to enabled otherwise. It can't be disabled for UDP and TCP\_UDP groups. [SetSecurityGroups](https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_SetSecurityGroups.html) · [TargetGroupAttribute](https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_TargetGroupAttribute.html)

| Load balancer | Client IP preservation | Rule the target needs on the traffic port | Rule on the health check port |
| --- | --- | --- | --- |
| Has security groups | Either | Load balancer security group | Load balancer security group |
| No security groups | Enabled | Approved client addresses | Load balancer private addresses |
| No security groups | Disabled | Load balancer private addresses | Load balancer private addresses |

AWS states that a target rule referencing the load balancer's security group admits its traffic even when client IP preservation is on. Health checks are subject to the load balancer security group's outbound rules, not its inbound rules, so an outbound rule that blocks the health check port marks targets unhealthy. [NLB security groups](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-security-groups.html) · [NLB target groups](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-target-groups.html)

A move from EC2 `bridge` tasks to `awsvpc` or Fargate tasks changes the target type from `instance` to `ip`. For a TCP group, that also changes the default from preserving client addresses to not preserving them, so the source the new tasks see differs from what the old instances saw.

## Read the four settings that decide the path

Use a read-only profile and replace the uppercase placeholders. First, the load balancer's security groups and the target group's health check. [describe-load-balancers](https://docs.aws.amazon.com/cli/latest/reference/elbv2/describe-load-balancers.html) · [describe-target-groups](https://docs.aws.amazon.com/cli/latest/reference/elbv2/describe-target-groups.html) · [describe-target-group-attributes](https://docs.aws.amazon.com/cli/latest/reference/elbv2/describe-target-group-attributes.html)

```
aws elbv2 describe-load-balancers \
  --profile PROFILE --region REGION --load-balancer-arns LB_ARN \
  --query 'LoadBalancers[0].{type:Type,vpc:VpcId,securityGroups:SecurityGroups,zones:AvailabilityZones[].SubnetId}' \
  --output json --no-cli-pager

aws elbv2 describe-target-groups \
  --profile PROFILE --region REGION --target-group-arns TARGET_GROUP_ARN \
  --query 'TargetGroups[0].{protocol:Protocol,port:Port,targetType:TargetType,hcProtocol:HealthCheckProtocol,hcPort:HealthCheckPort,hcPath:HealthCheckPath,codes:Matcher.HttpCode}' \
  --output json --no-cli-pager

aws elbv2 describe-target-group-attributes \
  --profile PROFILE --region REGION --target-group-arn TARGET_GROUP_ARN \
  --query 'Attributes[?Key==`"preserve_client_ip.enabled"`]' \
  --output json --no-cli-pager
```

`HealthCheckPort` defaults to `traffic-port`, the port each target receives traffic on. If it names a fixed port, the security group must admit that port too. [CreateTargetGroup](https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_CreateTargetGroup.html)

Then compare the security groups of the old and new ECS deployments, and read the new group's inbound rules. [Deployment fields](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_Deployment.html) · [describe-security-group-rules](https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-security-group-rules.html)

```
aws ecs describe-services \
  --profile PROFILE --region REGION --cluster CLUSTER --services SERVICE \
  --query 'services[0].deployments[].{status:status,definition:taskDefinition,securityGroups:networkConfiguration.awsvpcConfiguration.securityGroups,subnets:networkConfiguration.awsvpcConfiguration.subnets}' \
  --output json --no-cli-pager

aws ec2 describe-security-group-rules \
  --profile PROFILE --region REGION --filters Name=group-id,Values=NEW_TASK_SG_ID \
  --query 'SecurityGroupRules[?IsEgress==`false`].{protocol:IpProtocol,from:FromPort,to:ToPort,cidr:CidrIpv4,group:ReferencedGroupInfo.GroupId,prefixList:PrefixListId}' \
  --output table --no-cli-pager
```

When the load balancer has no security groups, find its private addresses, the sources of its health checks. List the load balancer network interfaces in its VPC and match them to its subnets. [describe-network-interfaces](https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-network-interfaces.html)

```
aws ec2 describe-network-interfaces \
  --profile PROFILE --region REGION \
  --filters Name=interface-type,Values=network_load_balancer Name=vpc-id,Values=VPC_ID \
  --query 'NetworkInterfaces[].{subnet:SubnetId,ip:PrivateIpAddress,description:Description}' \
  --output table --no-cli-pager
```

Last, read target health for old and new targets together. [describe-target-health](https://docs.aws.amazon.com/cli/latest/reference/elbv2/describe-target-health.html)

```
aws elbv2 describe-target-health \
  --profile PROFILE --region REGION --target-group-arn TARGET_GROUP_ARN \
  --query 'TargetHealthDescriptions[].{target:Target.Id,port:Target.Port,hcPort:HealthCheckPort,state:TargetHealth.State,reason:TargetHealth.Reason,description:TargetHealth.Description}' \
  --output table --no-cli-pager
```

## What each result means

| New targets | Rule check | Likely cause | Next check |
| --- | --- | --- | --- |
| Unhealthy; old targets healthy | New group has no rule for the load balancer's source on the health check port | Security group | Compare with the old deployment's group |
| Unhealthy; every target | Rules admit the source | The load balancer's outbound rules, a network ACL, or the health check settings | `SecurityGroupBlockedFlowCount_Outbound_TCP` and the target group's health check |
| Healthy; clients time out | Preservation on, no load balancer group, rules admit only the VPC range | Client traffic dropped | A rule for approved client addresses on the traffic port |
| Unhealthy | Rules admit the source; a request to the health path from inside the VPC returns a status outside the matcher | Application: it answered the HTTP check with another status | The new tasks' logs for the health path |
| Unhealthy | Rules admit the source; a connection from inside the VPC is refused | Application not listening on the port | The container port in the new task definition |

On a Network Load Balancer, an unhealthy target reports `Target.FailedHealthChecks` whatever went wrong: a dropped connection, a refused one or an HTTP status outside the matcher. The more specific `Target.ResponseCodeMismatch` and `Target.Timeout` apply only to Application and Gateway Load Balancers, so the reason code does not separate the network from the application here. The separating step is the one AWS gives for a target that won't enter service: from an instance or task inside the VPC whose security group the target admits, connect to the target's private address on the health check port, and for an HTTP check request the health path and read the status.

```
# From inside the VPC, read-only: prints the status the health check would see.
curl -sS -o /dev/null -w 'status=%{http_code} connect=%{time_connect}\n' --connect-timeout 3 --max-time 10 http://TARGET_IP:HEALTH_CHECK_PORT/HEALTH_CHECK_PATH
```

A status outside the target group's `Matcher` means the application answered, so the path is open. Read where it stopped. A connect timeout (`curl` exit code 28 with `connect=0.000000`) from a source the rules admit points back at a network ACL or routing. A connection that opens but returns no status before `--max-time` is a stalled handler, and a refused connection is a process not listening; both belong to the application. [TargetHealth](https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_TargetHealth.html) · [Troubleshoot your Network Load Balancer](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-troubleshooting.html)

For a load balancer with security groups, `SecurityGroupBlockedFlowCount_Inbound_TCP` and `SecurityGroupBlockedFlowCount_Outbound_TCP` count new TCP flows that its own groups rejected. Traffic those groups block appears in no other metric, and AWS points to VPC Flow Logs for per-flow detail. [NLB CloudWatch metrics](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-cloudwatch-metrics.html)

## An illustrative fixture: one symptom, two causes

This fixture is fictional. The service `orders` runs on Fargate behind `orders-nlb`, a TCP listener on port 9000 forwarding to an `ip` target group with an HTTP health check on `/healthz`. The load balancer has security group `sg-nlb`. Task definition `orders:58` started rolling out at 10:00 UTC.

In the first reading, both `orders:58` targets are unhealthy and both `orders:57` targets are healthy. The new deployment lists security group `sg-orders-v2`, created for this release, and its only inbound rule admits port 8080 from `sg-nlb`. Port 9000 has no rule. The fix is an inbound rule on port 9000 from `sg-nlb`, and the release code is not involved.

In the second reading, the deployment kept `sg-orders`, whose rule admits port 9000 from `sg-nlb`. The new targets show `Target.FailedHealthChecks`, the code a dropped connection would also give. A request to `/healthz` on a new task's address from inside the VPC returns 503, so the application answered. In this fixture, `orders:58` added a cache check to `/healthz` that fails, and the new tasks' logs show it. Changing security groups would not help.

## Change the rule and confirm on a replacement task

This command changes the security group. Scope the rule to the load balancer's group, or to its private addresses when it has no group. [authorize-security-group-ingress](https://docs.aws.amazon.com/cli/latest/reference/ec2/authorize-security-group-ingress.html)

```
# Change: admit the load balancer on the traffic port
aws ec2 authorize-security-group-ingress \
  --profile PROFILE --region REGION --group-id NEW_TASK_SG_ID \
  --ip-permissions 'IpProtocol=tcp,FromPort=TRAFFIC_PORT,ToPort=TRAFFIC_PORT,UserIdGroupPairs=[{GroupId=NLB_SG_ID}]' \
  --output json --no-cli-pager
```

Add the health check port the same way if it differs. Then read `describe-target-health` again. The targets should move through `initial` with `Elb.InitialHealthChecking` to `healthy`. If ECS already replaced the failing tasks, read the replacements. When client IP preservation is on, a healthy target shows only that the health check path is open, so confirm the client path with a request from an approved client network.

## Where the reading stops

`describe-target-health` is a snapshot. ECS stops tasks that fail load balancer health checks and starts replacements, so read it while the failure is live. A security group is only one filter on the path: the network ACLs on the target and load balancer subnets filter the same traffic, including its return path. A rule that references the load balancer's group does not cover a load balancer created without security groups, and a VPC range rule that admits health checks says nothing about client traffic when addresses are preserved. When an Auto Scaling group registers instances in the target group and uses load balancer health checks, the same failures can lead it to [replace new instances](/learn/asg-elb-health-check-replaces-new-instances/). [ECS load balancer considerations](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/load-balancer-types.html) · [Troubleshoot your Network Load Balancer](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-troubleshooting.html)

A healthy new target can still drop clients during the next deploy for another reason: see [long-lived connections during deregistration](/learn/nlb-deregistration-long-lived-connections/).

## Questions

### Why are NLB targets unhealthy when the security group allows the load balancer?

Check which port the rule admits against `HealthCheckPort`, and check the load balancer security group's outbound rules, which govern health checks. If both are open, the reason code will not tell you more: a Network Load Balancer reports `Target.FailedHealthChecks` for every failed check. Request the health path on the target's address from inside the VPC; a status outside the matcher means the application is failing the check.

### Does client IP preservation change which security group rule an NLB target needs?

Yes, when the load balancer has no security groups: targets see client addresses, so the traffic port needs a rule for approved clients while health checks still come from the load balancer's private addresses. When the load balancer has security groups, a rule referencing its group admits its traffic either way.

### Can I add a security group to an existing Network Load Balancer?

Only if the load balancer was created with at least one security group. Without one, you change the target security groups instead, using the load balancer's private addresses and, with client IP preservation, the client addresses.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Long-lived TCP connections drop during an NLB deploy](/learn/nlb-deregistration-long-lived-connections/)
    
    Network outages The Proofline team November 22, 2026 7 min read
    
-   ### [AWS deployment failure signatures: startup, placement, health, routing or scaling](/learn/aws-deployment-failure-signatures/)
    
    Deployment failures The Proofline team November 22, 2026 9 min read
