# session persistance using x-forward-for

**URL:** <https://community.f5.com/t/session-persistance-using-x-forward-for/5471>\
**Category:** Technical Forums\
**Tags:** irules, big-ip, application-delivery\
**Created:** [February 3, 2016, 8:08pm UTC](https://community.f5.com/t/session-persistance-using-x-forward-for/5471 "2016-02-03T20:08:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SteveT\_240596](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@SteveT\_240596](https://community.f5.com/u/SteveT_240596)\
**Post date:** [February 3, 2016, 8:08pm UTC](https://community.f5.com/t/session-persistance-using-x-forward-for/5471/1 "2016-02-03T20:08:36Z")

</div>

The traffic coming to our virtual server is being reverse proxied from 2 TMG servers meaning we only see 2 source IP addresses. The header does contain the x-forward-for address of the original client. Our application team wants us to load balance this traffic across 3 web servers with session persistence. We have tried using the iRule below from an example we found but it does not appear to work. We are new to F5 so appreciate any assistance.

when HTTP\_REQUEST { if {[HTTP::header exists “X-Forwarded-For”] }{

persist uie [HTTP::header X-Forwarded-For] 1830 log local0. “PATTS X-Forwarded-For: [HTTP::header X-Forwarded-For]”

---

<div class="post-metadata">

**Author:** ![Kai\_Wilke](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kai_wilke/32/24646_2.png) [@Kai\_Wilke](https://community.f5.com/u/Kai_Wilke)\
**Post date:** [February 3, 2016, 9:30pm UTC](https://community.f5.com/t/session-persistance-using-x-forward-for/5471/2 "2016-02-03T21:30:58Z")

</div>

Hi Steve,

you may try the snippet below…

```tcl
when HTTP_REQUEST { 
    if { [HTTP::header value "X-Forwarded-For"] ne "" } then {
         log local0. "PATTS \"X-Forwarded-For\" header: [HTTP::header value "X-Forwarded-For"]"
        persist uie [HTTP::header value "X-Forwarded-For"] 1830 
    } else {
         log local0. "No \"X-Forwarded-For\" header found."
    }
}

```

_ **Note:** I duno if you posted just the half iRule for illustration purposes? I’ve completed then given iRule, tweaked here and there a little bit the syntax and added an additional [log] statement to get some ouput if no X-Forwarded-For header is not present or somehow empty._

Cheers, Kai

---

<div class="post-metadata">

**Author:** ![SteveT\_240596](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@SteveT\_240596](https://community.f5.com/u/SteveT_240596)\
**Post date:** [February 4, 2016, 4:21pm UTC](https://community.f5.com/t/session-persistance-using-x-forward-for/5471/3 "2016-02-04T16:21:22Z")

</div>

Kai thanks for the response.

---

<div class="post-metadata">

**Author:** ![Kai\_Wilke](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/kai_wilke/32/24646_2.png) [@Kai\_Wilke](https://community.f5.com/u/Kai_Wilke)\
**Post date:** [February 4, 2016, 7:27pm UTC](https://community.f5.com/t/session-persistance-using-x-forward-for/5471/4 "2016-02-04T19:27:09Z")

</div>

You’re welcome!
