# Get IP Client in a plugin

**URL:** <https://discuss.konghq.com/t/get-ip-client-in-a-plugin/880>\
**Category:** Questions\
**Created:** [April 25, 2018, 8:29am UTC](https://discuss.konghq.com/t/get-ip-client-in-a-plugin/880 "2018-04-25T08:29:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![i3yaki](https://avatars.discourse-cdn.com/v4/letter/i/b77776/32.png) [@i3yaki](https://discuss.konghq.com/u/i3yaki)\
**Post date:** [April 25, 2018, 8:29am UTC](https://discuss.konghq.com/t/get-ip-client-in-a-plugin/880/1 "2018-04-25T08:29:05Z")

</div>

Hello,

I am a student in IT and for a project I am looking for a way to get the IP Client when I am doing an HTTP Request on Kong.  
I read [How to Forward Client’s request IP](https://discuss.konghq.com/t/how-to-forward-clients-request-ip/384)  
Maybe I just didn’t understand but I tried to get the IP Client in a log but I always get the same address : 10.0.2.2  
I read something about nginx http module but I don’t understand how to use it or if Kong already implemented it.  
Is someone have an easy solution ?

Thanks

---

<div class="post-metadata">

**Author:** ![kikito](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/kikito/32/15_2.png) [@kikito](https://discuss.konghq.com/u/kikito)\
**Post date:** [April 25, 2018, 9:55am UTC](https://discuss.konghq.com/t/get-ip-client-in-a-plugin/880/2 "2018-04-25T09:55:29Z")

</div>

Please try using `ngx.var.remote_addr` ([reference](http://nginx.org/en/docs/http/ngx_http_core_module.html#var_remote_addr))

If this does not work, please add more data: how exactly are you getting that `10.0.2.2` IP address? Also please add what version of Kong are you using, and any specifics that you might have: plugins, custom nginx configurations, etc.

---

<div class="post-metadata">

**Author:** ![i3yaki](https://avatars.discourse-cdn.com/v4/letter/i/b77776/32.png) [@i3yaki](https://discuss.konghq.com/u/i3yaki)\
**Post date:** [April 25, 2018, 11:15am UTC](https://discuss.konghq.com/t/get-ip-client-in-a-plugin/880/3 "2018-04-25T11:15:25Z")

</div>

The `10.0.2.2` comes from the `ngx.var.remote_addr`.  
Sorry for the lack of informations.  
My Kong is started by Docker in a Virtual Box launched with Windows 10.  
The version of Kong is 0.13.0.  
And for the plugin used, this is a custom plugin. Just a simple hello world in the error logs.  
I just add a `ngx_log(ngx.ERR, ngx.var.remote_addr)`.  
I tried `ngx_log(ngx.ERR, ngx.var.realip_remote_addr)`, but I still have the same response : 10.0.2.2  
My tutor said that maybe it is because of my virtual machine. And after some searches it seems that this is the case. But how can I get the real IP Client ? Because I would like to execute some command depending on the IP address of the Client.

Thanks for your help 🙂

---

<div class="post-metadata">

**Author:** ![kikito](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/kikito/32/15_2.png) [@kikito](https://discuss.konghq.com/u/kikito)\
**Post date:** [April 25, 2018, 1:36pm UTC](https://discuss.konghq.com/t/get-ip-client-in-a-plugin/880/4 "2018-04-25T13:36:58Z")

</div>

> [@i3yaki](#):
>
> My tutor said that maybe it is because of my virtual machine

I agree with your tutor’s assessment.

> [@i3yaki](#):
>
> But how can I get the real IP Client

That is more a Docker question than a Kong question. Try disabling the network containerization by using the `--network=host` option when you create your container. This option is described [on the Docker docs](https://docs.docker.com/network/host/)

---

<div class="post-metadata">

**Author:** ![i3yaki](https://avatars.discourse-cdn.com/v4/letter/i/b77776/32.png) [@i3yaki](https://discuss.konghq.com/u/i3yaki)\
**Post date:** [April 25, 2018, 2:03pm UTC](https://discuss.konghq.com/t/get-ip-client-in-a-plugin/880/5 "2018-04-25T14:03:36Z")

</div>

Docker stop immediatly if I use the network option.  
But as my tutor and you agree, the problem was my virtual machine.  
That is why I made an Nginx Reverse Proxy from my Windows to make my HTTP Request, I use X\_FORWARDED\_FOR thing to set the ngx.var.http\_x\_forwarded\_for which was nil.  
And now I retrieve the good address IP.

Thanks for your help 😃.

---

<div class="post-metadata">

**Author:** ![bungle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/bungle/32/13_2.png) [@bungle](https://discuss.konghq.com/u/bungle)\
**Post date:** [April 25, 2018, 7:36pm UTC](https://discuss.konghq.com/t/get-ip-client-in-a-plugin/880/6 "2018-04-25T19:36:22Z")

</div>

@i3yaki, please read this:

> [@How to Forward Client's request IP](https://discuss.konghq.com/t/how-to-forward-clients-request-ip/384/2):
>
> Hi, This is a typical behavior/drawback of many reverse-proxies and load-balancers. Luckily for you, and as one would expect, there exist ways to circumvent them! Retrieving the client IP in your API First and foremost, Kong will set the [X-Forwarded-For](https://en.wikipedia.org/wiki/X-Forwarded-For) header for you since 0.11.0. You can use its value in your upstream services to retrieve the client IP. This is, I believe, the answer you are looking for. But let’s take a deeper dive here, because there are other important areas around this …
