All Documents
Current Document

Content is empty

If you don't find the content you expect, please try another search term

Documentation

How do I get the actual IP of the user on the server?

Last updated:2023-05-22 19:48:05

If KAD is enabled, the IP address recorded in access logs of a web server will be the IP address of a KAD instance, and the real IP addresses of clients are hidden.

Obtain real IP addresses of clients on a web server

If you add an HTTP header to the packets forwarded by KAD, the web server can then record real IP addresses of clients in logs.

Example of the HTTP header in NGINX:

'$http_x_forwarded_for - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer"' '"$http_user_agent" ';

Example of the HTTP header in Apache:

LogFormat "%{X-FORWARDED_FOR}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""

Example of the HTTP header in ASP:

Request.ServerVariables("X_FORWARDED_FOR")

Example of the HTTP header in PHP:

$_SERVER["HTTP_X_FORWARDED_FOR"]

Example of the HTTP header in JSP:

request.getHeader("X_FORWARDED_FOR")

Obtain real IP addresses of clients on a non-web server

You can use the following method to obtain real IP addresses of clients on an origin server running CentOS or Fedora OS. For other operating systems, consult the Kingsoft Cloud technical support team.

  1. Run the uname -r command to view the kernel version of the host.

image.png

  1. Download the RPM package for your operating system.

2.6.32_358

2.6.32_504

2.6.32_696

3.10.0_229

3.10.0_327

3.10.0_514

3.10.0_693

  1. Install the RPM package.

image.png

If your host kernel version is not in the preceding list, you can compile the source code to install the RPM package. The procedure of installing the RPM package on the origin server running CentOS is as follows (if your origin server is running another operating system, consult the Kingsoft Cloud technical support team):

Step 1: View the kernel version.

If the kernel version is 3.10.0-957.1.3.el7.x86_64, the source code is as follows:

 # uname -r 
 # 3.10.0-957.1.3.el7.x86_64

Step 2: Download the RPM package based on the kernel version.

Download the centosrpm package, and find the RPM package corresponding to the kernel version.

If the RPM package is not found, you can obtain it from the CentOS official website at https://wiki.centos.org/HowTos/I_need_the_Kernel_Source.

# rpm -ivh kernel-devel-3.10.0-327.el7.x86_64.rpm

Step 3: Install dependencies.

# sudo yum install rpm-build redhat-rpm-config asciidoc hmaccalc perl-ExtUtils-Embed pesign xmlto
$ sudo yum install audit-libs-devel binutils-devel elfutils-devel elfutils-libelf-devel gcc
$ sudo yum install ncurses-devel newt-devel numactl-devel pciutils-devel python-devel zlib-devel

Step 4: Compile and install the TTM module.

Download the TTM source code

# unzip centos-kgwttm_v4.zip
# cd kgwttm
# ./build.sh 
# rpm -ivh *.rpm
# sh /usr/local/bin/kgwttm-insmod.sh
# lsmod |grep kgwttm
On this page
Pure ModeNormal Mode

Pure Mode

Click to preview the document content in full screen
Feedback