Header Ads

Recently post

How to create irule in F5

How to create irule in F5

  1. On the Main tab, click Local Traffic > iRules.
  2. Click Create.
  3. In the Name field, type a name, such as my_irule







Example :

Just example if we want to redirect http://xyz.com its redirect to https://xyz.com

when HTTP_REQUEST {

 if { [HTTP::host] equals "xyz.com"} {

  HTTP::redirect "https://[HTTP::host][HTTP::uri]"

  }

 }


Nexp step - Add the iRule to your HTTP virtual server in the "Resouces" tab/section

Note : instead of equals you can use other operators from "equals" to "starts_with", "contains", and "ends_with".


------

Next IRULE we can use based on Cookies value we can use backed servers or forward traffic.

Please note : log local0. only used for logs purpose once you done your testing you can remove this because its generate huge logs.

Example :

Pool Name- Test_POOL_HTTP

Pool member ip - 192.168.1.1:80, 192.168.1.2:80

Cookies value: xyz, abc

-------------------------------------------------------------------------------------------------------------------

when HTTP_REQUEST {

log local0. "HTTP Rquest  RECEIVED"

log local0. "[HTTP::cookie value "SessionID"]"

    if { [HTTP::cookie exists "SessionID"] } {

        if {[HTTP::cookie value "SessionID"] contains "xyz" } {

                if { [LB::status pool Test_POOL_HTTP member 192.168.1.1 80] eq "up" } {

                    pool Test_POOL_HTTP member 192.168.1.1 80

                }

                else {

                    pool Test_POOL_HTTP member 192.168.1.2 80

                }

                log local0. "[HTTP::cookie value "SessionID"] and user has gone to specific 192.168.1.1-------Client Connected, IP: [IP::client_addr]"

            }

        elseif {[HTTP::cookie value "SessionID"] contains "abc" } {

                 if { [LB::status pool Test_POOL_HTTP member 192.168.1.2 80] eq "up" } {

                    pool Test_POOL_HTTP member 192.168.1.2 80

                }

                else {

                    pool Test_POOL_HTTP member 192.168.1.1 80

                }

                log local0. "[HTTP::cookie value "SessionID"] and user has gone to specific 192.168.1.2-----Client Connected, IP: [IP::client_addr]"

        }

        else {

            pool Test_POOL_HTTP member 192.168.1.1 80

        }

    }

}


---------------------------------------------------------------










No comments