How can I route requests based on the source IP using an Application Load Balancer?

Last updated: 2020-09-23

I want to perform specific actions on requests based on the source IP address of the request. This might include sending custom responses to specific users, or serving different versions of an application to a certain set of users. How can I do this using an Application Load Balancer?


There are several use cases in which you might want to perform specific actions based on the source IP address of a request. For example, let's say that you have two versions of an application. One version is a public version that's meant for global users. The other is an internal version that includes some extended (beta) features. You might only want the internal version to be available to employees accessing the application from corporate network CIDRs. To accomplish this, and many other similar tasks, you can configure listener rules based on source IP addresses.

Before you begin, keep in mind that a rule based on source IP checks the source IP address in the IP header (layer-3). If there's a proxy or firewall between the client and the Application Load Balancer that changes the source IP address, specify the firewall or proxy's IP address in the listener rule.

Also, avoid using listener rules to block requests from clients. It's a best practice to use security groups or network access control lists instead. To block a large number of clients, you can use AWS WAF.

  1. Create an Application Load Balancer, if you don't already have one.
  2. Open the Amazon Elastic Compute Cloud (Amazon EC2) console.
  3. On the navigation pane, under Load Balancing, choose Load Balancers.
  4. Select your load balancer.
  5. Choose the Listeners tab.
  6. Select your listener, and then choose View/edit rules.
  7. Choose the Add rules icon (the plus sign), and then choose Insert rule.
  8. Choose Add condition, and then choose Source IP.
  9. Specify the IP addresses for which you plan to configure a different action.
    Note: You can specify either a single IP address or network CIDRs with prefixes. For example, "" or "".
  10. Choose Add action, and then select the required action. For example:
    Forward – To forward to a different target group. (Such as forwarding to a target group running an internal version of an application.)
    Return fixed response – To block specific users or provide custom responses to specific users.
  11. To save the condition, choose the checkmark icon.
  12. To save the rule, choose Save.

Did this article help?

Do you need billing or technical support?