If your users jump through proxies and lode balancers before accessing to your web application, the IP field in IIS logs may show the IP address of a network device rather of node ’ s IP address. In this mail, I will explain how to log actual customer ’ s IP address in this scenario .

Long report short : You can use X-Forwarded-For request header to find and log the IP address of the node. This field is not logged in IIS by default so that you need to manually add it .

 

Steps to log actual client IP address

You can use custom logging to add X-Forwarded-For field. The way custom logging works is different based on IIS adaptation. I am including two sets of instructions below for different versions.

The directory the custom-made logs are stored in :

  • In IIS 7/7.5/8: %SystemDrive%\inetpub\logs\AdvancedLogs
  • In IIS 8.5+: %SystemDrive%\inetpub\logs\LogFiles

 

Add X-Forwarded-For column in IIS 7/7.5/8

  1. Open IIS Manager
  2. On server, site or application level, double click “Advanced Logging
  3. In the action pane on right side, click “Enable Advanced Logging
  4. In the action pane, click “Edit Logging Fields
  5. In the new window, click “Add Field
  6. In “Add Logging Field” window, fill out the following fields
  • Field ID: X-Forwarded-For, Source type: Response Header, Source name: X-Forwarded-For
  • Click “OK
  • In the middle pane, select the default log definition %COMPUTERNAME%-Server. Click “Edit Log Definition
  • Click “Select Logging Fields” 
  • Select “X-Forwarded-For” from the list. Click “OK
  • Click “Apply” in the actions pane
  • After these steps, wait for a new log file to be created. Column changes will be effective merely after a new log file is created. You may need to generate some traffic to fill the current logarithm file .

     

    Powershell

    here is the PowerShell command to add X-Forwarded-For header at the server level .

    Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.applicationHost/sites/siteDefaults/logFile/customFields" -name "." -value @{logFieldName='X-Forwarded-For';sourceName='X-Forwarded-For';sourceType='RequestHeader'}

     

    Add X-Forwarded-For column in IIS 8.5 and newer versions

    Custom log became easier to configure with the IIS 8.5. Follow the steps below to add X-Forwarded-For column into IIS logs .

    1. Open IIS Manager
    2. On server, site or application level, double click “Logging
    3. Click “Select Fields
    4. In “W3C Logging Fields” window, click “Add Field
    5. In the “Add Custom Field” window, fill out the following fields
    • Field Name: X-Forwarded-For, Source type: Request Header, Source: X-Forwarded-For
  • Click “OK” in both open windows
  • Click “Apply” in the actions pane
  • note : Check out this post for more screenshots.

    IIS-custom-field-1.png
    Wait for a new log file to be created in the log booklet. Column changes will be effective when a new log file is created .

    Note 1:  If you see a dash ( “ – “ ) alternatively of an IP address in X-Forwarded-For column, it means the customer didn ’ thymine function any proxies or cargo balancers. consequently, the client IP must be logged in the “ c-ip ” column

    Note 2: If you see multiple IP addresses in X-Forwarded-For column, it means the customer went through more than one network device. Each network device adds their own IP to the end of the value. The left-most IP address is the actual client IP cover. Others belong to net devices the customer go through .

    X-Forwarded-For : client1, proxy1, proxy2, …

     

    ARR Helper

    If you implemented node IP address by using ARR Helper in IIS 7 and wondering how to do the same in IIS 10, follow the steps below .
    alternatively of using arr_helper_x64.msi, use requestrouterhelper_x64.msi in IIS 10 :

    1. Install ARR 3.0 to a server. It doesn’t have to be an IIS server you actually use. We need ARR 3.0 installation just to get requestrouterhelper_x64.msi from its folder
    2. Go to installation directory (%ProgramFiles%\IIS\Application Request Routing). Copy requestrouterhelper_x64.msi to your IIS server
    3. Open a Command Prompt in that folder. Run “install requestrouterhelper_x64.msi”

     

    References:

    generator : https://themedipia.com
    Category : Website hosting

    Leave a Reply

    Your email address will not be published.