This article describes how to enable client IP in TCP/IP option of NetScaler.
Currently, several customers are trying to make use of the NetScaler as a centralized resource to perform load balancing for many applications in large data centers. When NetScaler application switch is used as >= L3 switch, it is setup as a proxy as many servers are across an L3 network. We need to operate as a proxy for such environments, however this results in the loss of the client’s source IP. As a result, we need to insert the client’s connection information as part of the initial data stream.
For HTTP and SSL services this is done by inserting ClientIP address as HTTP Header on the request to the server. Inserting Client IP address header is not possible for TCP based services . So we can use TCP header insertion as an alternative.
This drawback is solved by this feature. After the three way handshake with the server, a single packet of additional data will be sent to the server. This data will be prepended with the 32 bit binary representation of the value entered as the CIP header, and then the complete TCP/IP header information for the packet that induced the backend connection to be established. This data starts with the start of the IP header to the end of the TCP header, including IPv6 extension headers, IPv4 options, and TCP options as appropriate. As such, proper logic in the application will need to be incorporated to ensure that the proper fields are being parsed.
Note that this feature does not work on HTTP load balancing virtual server/service.
An extra packet is sent by the NetScaler to the server side containing the following information
Screen shots of sample trace
Note: In SSL_BRIDGE NetScaler TCP does not proxy the final packet from client to the server side. On the final ACK, protocol control block (PCB, TCP session structure) itself is not created on the NetScaler. We do this because we know that this is an SSL protocol and client has to send first data packet (SSL client hello), only then PCB is allocated on NetScaler for the client side connection and IP+TCP header is stored from this client hello packet and forwarded to the sever side and client side information. If suppose client hello may be 265 bytes, so we will see the IP len as 265 bytes.
In our Lab we successfully tested this feature for following services:
Complete the following steps to enable client IP in TCP/IP option of NetScaler:
Go to the CLI of NetScaler and type:
set ns param -tcpCIP EnabLED
Name the service which needs the header to be inserted. Magic number only supports numerical value so provide only numbers here else it will not work.
set service <service name> -cip enabled <magic number>
For Example - set service farhan -cip ENABLED 1234
Make sure the service are of type TCP or SSL Bridge or SSL_TCP. It is not supported for HTTP load balancing server/services.
Verify the settings through GUI. Navigate to System > Setting > Change Global System Settings and make sure that Client TCP/IP header insertion in TCP payload is enabled.
On the service the CIP is enabled and Magic number is given in a numeric format.
Note: Magic number does not support alphabets or symbol.
Make sure that the service are not HTTP type as it does not work for HTTP type service or load balancing virtual server.
After 3 way handshake you will see one more ACK packet just after the ACK packet of 3 way handshake which is sent by SNIP (10.104.23.132) to the backend server (10.104.23.149) and has some length, like here it shows length as 52
Select the TCP header and it will show highlighted part:
After this you will see in the Hex format as shows 000004d20000003400010028... string.
After the highlighted part find out the first occurrence of 00 28 which is the CIP header size.
Now from this 00 28 move right to the next 12 hex values.
After these value note down the next 4 value which will be 0a 67 06 1e and which is our client IP address 10.103.6.30.
Now to go any site for hex to IP converter and give these value and convert them which will show the actual client IP which is 10.103.6.30 in my case.
So NetScaler will be sending the client IP in the TCP data. The backend server should have proper setting to understand it and extract the client IP value from TCP header.