Forum Discussion

Huw_Jenkins_425's avatar
Huw_Jenkins_425
Icon for Nimbostratus rankNimbostratus
Dec 01, 2006

Preserve Client IP in HTTP Header when using SNAT

Hi

 

 

i am trying to configure an iRule to preserve the client ip address when connecting to a VS. i have configured the following iRule, and added to the VS, but when i view the IIS logs on the web server they are still showing up the LB address. any ideas where how I

 

 

when HTTP_REQUEST {

 

HTTP::header insert ORIG_CLIENT_IP [IP::remote_addr]

 

}

 

 

i am new to iRules so any help would be grateful, thanks

 

 

7 Replies

  • I think the only thing wrong with your iRule is that you're using [IP::remote_addr] instead of [IP::client_addr]. Be definition, you're using the end IP, not the start.

    However, if you're trying to add this header to ALL traffic on that virtual server without putting in any additional logic, you'd be better off simply adding the header in the HTTP profile. There is a "Header Insert" option there where you could place it instead. Instead of the syntax you used above, I believe it would be

    ORIG_CLIENT_IP:[IP::client_addr]

    (Edit - I mistyped the one above the first time. Oops...)

    Also, note the option in there called "Insert XForwarded For." This does the exact same thing you're trying to do, except the name of the header is "X-Forwarded-For" instead of "ORIG_CLIENT_IP".
  • I think deathbywedgie's suggestion is easier to insert the original client IP address in the XFF header, than using a rule.

     

     

    We also have an IIS plugin you can install on the web servers to parse the header. Check this post for details:

     

     

    Click here

     

     

    Aaron
  • Hello,

     

    I tried your sugestion of inserting a custom header to replace the client IP but I am still getting the SNAT IP in the ISS logs. Do you have this functionalty working? I am not keen to use the x-forward header as this would require an ISAPI filter to be installed on the IIS server which (unfortunately) is not an option.

     

     

    How does the ISS log interpret the ORIG_CLIENT_IP & change it into the W3C format c-ip (client IP)? Should the header be c-ip:[IP::client_addr]?
  • IIS won't log custom headers by default, which is why the DLL is necessary. The source code for the DLL is included, so you can see what it is doing if that's your concern.

     

     

    Else, you could reconfigure your network so you don't need to enable source address translation. This seems like a drastic step to take just to avoid installing a DLL/get the correct client IP address logged.

     

     

    Aaron
  • Thanks Guys

     

     

    I have now managed to get this working, i downloaded the dll as mentioned, installed it as an ISAPI filter on the web server, Enababled "Insert XForwarded For " in the http profile, and removed my attempt at writing an irule. Now when i look in the IIS Logs on teh web server the source address appears instead of the LB address

     

     

  • hello guys

     

    how did we do to install the dll, please?

     

    i'm using a big IP 4.5.10 and i can't log the ip adresses

     

    pool my_pool {

     

    header insert "OrigClientAddr:${client_addr}"

     

    ...

     

    }

     

    it doesn't work, i don't know why!!!

     

    need your help
  • Make sure to put a space between the header name and value:

     

     

    header insert "OrigClientAddr: ${client_addr}"

     

     

    You then need to install the F5 X-Forwarded-For DLL for IIS on your Windows server to specify that the server should log the alternate header name. You can get more info on the DLL and download it from Joe's article here:

     

     

    http://devcentral.f5.com/weblogs/joe/archive/2005/09/23/1492.aspx

     

     

    Aaron