Forum Discussion
SNAT/X-Forwarded
Hey guys,
Bit of a weird one this. So I have 2 HA pairs both SNAT'ing but require the x forwarded to preserve the original source IP to due an access control for the client IP on the end server.
The traffic comes in on the first pair, I SSL offload, I then use server-side incompatible to pass it on the next pair. It then hits the next pair so would it be best just to make this pass through and then hit the SNAT again to reach the end server? I have in my head this would work but I may be missing something.
The key to it is basically having the original client IP available when it reaches the end server.
Thanks for the input!
Hi ,
you could either insert the
header just on the first HA pair and disable theX-Forwarded-For
insertation on the second HA pair (see HTTP Profile options).X-Forwarded-For
Alternatively you can use the following iRule on the second unit to consolidate multiple
's into a single header.X-Forwarded-For
when HTTP_REQUEST { if { [set x_forwarded [HTTP::header values "X-Forwarded-For"]] ne "" } then { HTTP::header remove "X-Forwarded-For" HTTP::header insert "X-Forwarded-For" "[join $x_forwarded ", "], [getfield [IP::client_addr] "%" 1]" } else { HTTP::header insert "X-Forwarded-For" "[getfield [IP::client_addr] "%" 1]" } }
The iRule will collect any existing X-Forwarded-For header values, then remove any existing X-Forwarded-For headers and finally create a new one with the collected values + the current "X-Forwarded-For" value. E.g.:
Incomming HTTP request headers:
GET / HTTP/1.1 Host: site.domain.de ... X-Forwarded-For: 1.1.1.1 X-Forwarded-For: 2.2.2.2, 3.3.3.3 X-Forwarded-For: 4.4.4.4
Outgoing HTTP request headers
GET / HTTP/1.1 Host: site.domain.de ... X-Forwarded-For: 1.1.1.1, 2.2.2.2, 3.3.3.3, 4.4.4.4, 5.5.5.5
Note: When using the iRule on your second HA pair, then make sure to disable the automatic X-Forwarded-For insert option in your HTTP profile on those devices. The insert will be already handled by this iRule...
Cheers, Kai
Hi Donster,
just the 1st pair has to insert the
header. This can be done by using a Standard VS with HTTP Profile attached and eitherX-Forwarded-For
HTTP Profile settings enabled or by disabling theX-Forwarded-For
HTTP Profile settings and deploying an iRule like this...X-Forwarded-For
when HTTP_REQUEST { HTTP::header remove "X-Forwarded-For" HTTP::header insert "X-Forwarded-For" [getfield [IP::client_addr] "%" 1] }
Note: You could also use the iRule of my previous post, if you need to consolidate existing
headers into a unified header.X-Forwarded-For
On the second unit you may also use a Standard VS with HTTP Profile attached - but you don't have to. If a HTTP Profile is getting attached, then you have to make sure that the
HTTP Profile settings are disabled.X-Forwarded-For
Cheers, Kai
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com