Logging the real client IP in IIS behind Citrix NetScaler

When IIS sits behind a Citrix NetScaler, your logs show the NetScaler's address instead of your visitors. NetScaler offers three ways to pass the client address on, and they behave very differently. Here is each one, with the CLI, and how to record the real client IP in the standard IIS log.

Short answer. By default NetScaler connects to your servers from one of its own addresses, a subnet IP (SNIP), so IIS logs that in c-ip. NetScaler's Insert Client IP Address option adds the real client to a request header; per service it is set service <name> -CIP ENABLED X-Forwarded-For. Name the header explicitly, because the NetScaler page we read does not state a default. IIS still ignores it, so log it as a column, as below, or validate it to correct c-ip.

On the NetScaler (CLI):

set service svc-iis-01 -CIP ENABLED X-Forwarded-For

On IIS, to see the header as a column (elevated PowerShell):

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'}

It adds a cs(X-Forwarded-For) column and does not change c-ip. Only need the column? The free custom log field covers that, and the section below says where it stops being enough.

Three ways to get the client address to IIS

MethodWhat NetScaler documentsEffect in IIS
Client IP header
-CIP ENABLED <header>
NetScaler inserts the client's address into the request header you name, per service. Whether it appends to or replaces an existing X-Forwarded-For is not stated on the page we read.Header only. c-ip still shows the SNIP.
USIP
set service <name> -usip YES
Disabled by default. NetScaler uses the client's IP address for communication with the servers. Citrix requires the server's gateway to be a NetScaler-owned SNIP so replies return through it. In current releases, HTTP connections are not reused while USIP is on.The connection comes from the client address, so the TCP source IIS logs in c-ip is the client's, with no header.
Rewrite policyCitrix's example (CTX218061) replaces any existing X-Forwarded-For with the single client address (replace ... CLIENT.IP.SRC), and a second rule inserts the header when it is absent. Citrix's documentation also has a rewrite example that deletes old X-Forwarded-For headers.Header only. A replace gives you one clean value rather than a chain.

Two details to watch. A global enable ns mode USIP applies only to services created after it is set. And Use Proxy Port matters only when USIP is on: Citrix documents it as on by default for TCP-based service types, and it makes NetScaler use its own port rather than the client's as the source port while still using the client address.

Lock the servers to the NetScaler

Restrict IIS at the firewall to the addresses NetScaler connects from, its SNIPs, so nobody can reach the server directly and supply their own header. With USIP on, the connection arrives from client addresses, so this lock-down does not apply in the same way and you rely on network placement instead.

The fix: X-Forwarded-For for IIS

Winfrasoft X-Forwarded-For for IIS is an ISAPI web filter that reads the header NetScaler inserts and writes the real client address into the standard IIS c-ip log field, with no application changes and no routing changes. It is the route for estates that stay on SNAT rather than moving to USIP.

Step by step

  1. On the NetScaler, enable the Client IP header on each service with an explicit header name, and confirm what arrives by logging it as a custom field.
  2. If a client-supplied X-Forwarded-For can reach the NetScaler, test whether your configuration appends to it or replaces it, since the documentation we read does not settle that. A replace policy removes the doubt.
  3. Install the filter on the IIS servers and set the header name to match.
  4. Populate the Proxy Trust List with the NetScaler's SNIP addresses and every other internal hop.
  5. Close the servers to everything except the NetScaler, then make a request and confirm c-ip holds the client address.

Is the free custom log field enough?

If all you need is the address somewhere in the log, IIS 8.5 and later can record the header as an extra column with no product, using the snippet at the top of this page. That appends a cs(X-Forwarded-For) column to the W3C log. It does not change c-ip.

For NetScaler there is a free route that does change c-ip: USIP, described above. It costs a routing change (the server gateway must be a NetScaler-owned address) and connection reuse, so it is not always possible, but if it is, you do not need a filter for the NetScaler hop.

It stops being enough when:

The click-through steps, and the log-file naming caveat, are in how to log X-Forwarded-For in IIS. If any of the points above applies, X-Forwarded-For for IIS 10 is the supported way to put the validated client address into c-ip itself.

Frequently asked questions

Does NetScaler send X-Forwarded-For to IIS by default?

Citrix presents the Client IP header as an option you enable per service, and the page we read names no default header, so set it explicitly with -CIP ENABLED X-Forwarded-For and confirm with a custom log field. We could not confirm a default state from an official page.

Should I use USIP or the Client IP header?

USIP makes the connection come from the client address, so c-ip is right without a header, but Citrix requires the server gateway to be a NetScaler-owned SNIP, and in current releases HTTP connections are not reused. The Client IP header keeps SNAT and routing as they are, at the cost of IIS still logging the SNIP until a filter reads the header.

Does the Client IP header append to an existing X-Forwarded-For?

The Citrix page for the setting does not say. A rewrite policy is documented separately: Citrix's example replaces the header with the single client address, and a second rule inserts it when it is absent. Test your own configuration before relying on either behaviour.

Which addresses go in the Proxy Trust List for NetScaler?

The SNIP addresses the NetScaler uses to connect to IIS, plus every other internal hop. Citrix documents that, by default, NetScaler picks the source address from a pool of SNIPs, so include the whole pool.

Get X-Forwarded-For for IIS

Log the real client IP in the standard IIS c-ip field behind Citrix NetScaler, with a Proxy Trust List so the value is validated rather than merely copied. IIS 10 on Windows Server 2016–2025, with a free 14-day trial.

View the product   or request a download →

Stuck on your setup? Email us with your proxy and what c-ip shows, and we will take a look.