# Kong integration with consul (its DNS interface) and dynamical routing

**URL:** <https://discuss.konghq.com/t/kong-integration-with-consul-its-dns-interface-and-dynamical-routing/3891>\
**Category:** Questions\
**Created:** [July 2, 2019, 2:01pm UTC](https://discuss.konghq.com/t/kong-integration-with-consul-its-dns-interface-and-dynamical-routing/3891 "2019-07-02T14:01:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![1112](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/1112/32/1145_2.png) [@1112](https://discuss.konghq.com/u/1112)\
**Post date:** [July 2, 2019, 2:01pm UTC](https://discuss.konghq.com/t/kong-integration-with-consul-its-dns-interface-and-dynamical-routing/3891/1 "2019-07-02T14:01:31Z")

</div>

hi!  
My issue :  
I use Kong as API gateway and Consul as a service discovery. Now i have 3 same services running on different random ports (for example user-service on port 44000 , 44001,44002).  
As i know consul has DNS interface.  
I want to be able to send 3 requests to kong (for example [http://127.0.0.1:8000/user-route/{here\_name\_of\_request\_mapping\_in\_my\_controller}](http://127.0.0.1:8000/user-route/%7Bhere_name_of_request_mapping_in_my_controller%7D)) and take response from 3 different services.  
Can someone explain please or refer to place where i can start?  
Sorry if this question is stupid) i’m learning. Thanks!

---

<div class="post-metadata">

**Author:** ![hbagdi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/hbagdi/32/562_2.png) [@hbagdi](https://discuss.konghq.com/u/hbagdi)\
**Post date:** [July 2, 2019, 4:21pm UTC](https://discuss.konghq.com/t/kong-integration-with-consul-its-dns-interface-and-dynamical-routing/3891/2 "2019-07-02T16:21:23Z")

</div>

Helllo @1112

Welcome to Kong Nation!

Please configure the `host` field of your [service](https://docs.konghq.com/1.2.x/admin-api/#service-object) object to point to the DNS name of your service in Consul and ensure Kong is using Consul for DNS resolution.

---

<div class="post-metadata">

**Author:** ![1112](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/1112/32/1145_2.png) [@1112](https://discuss.konghq.com/u/1112)\
**Post date:** [July 4, 2019, 7:03am UTC](https://discuss.konghq.com/t/kong-integration-with-consul-its-dns-interface-and-dynamical-routing/3891/3 "2019-07-04T07:03:26Z")

</div>

@hbagdi , Hello!  
thanks a lot for your quick response 🙏🙏🙏

i’ve done it . I want to leave comment how. maybe it will be helpful for someone.  
1)install and run consul  
2)register services with it (i made it with simple adding consul-discovery dependency in my pom.xml)  
3) open kong.conf and define dns\_resolver = 127.0.0.1:8600 ( By default, Consul will listen on 127.0.0.1:8600 for DNS queries in the `consul.` domain)  
4) create Service with Admin API (host should be like {your-service-name}.service.consul). port can be any. specify path (for me it was simple “/”)  
5) create Route for this service (define client host (for me it was my local machine - so localhost)) and paths (i made it /ss).  
6) By default Kong listens to 8000 port so  
i made get request to [http://127.0.01:8000/ss/loadbalance](http://127.0.01:8000/ss/loadbalance) (where /loadbalance - request mapping for my method in controller) with header “Host : 127.0.0.1”  
7) now it use round robin load balancer

p.s .  
I want to clarify.  
Just imagine that i have 100 microservices ( i think it possible) . And each of this microservices have own API with 5 methods for example.  
So i should use 100 calls to Admin API and set Routes and Services for each service ???

i used api gateway from spring cloud stack and i was able to route request by easily typing  
[http://localhost](http://localhost):(port\_of\_api\_gateway)/(name\_of\_service\_which\_i\_want\_to\_route)/(name\_of\_request\_mapping)

---

<div class="post-metadata">

**Author:** ![hbagdi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/hbagdi/32/562_2.png) [@hbagdi](https://discuss.konghq.com/u/hbagdi)\
**Post date:** [July 9, 2019, 12:54am UTC](https://discuss.konghq.com/t/kong-integration-with-consul-its-dns-interface-and-dynamical-routing/3891/4 "2019-07-09T00:54:22Z")

</div>

> [@1112](#):
>
> So i should use 100 calls to Admin API and set Routes and Services for each service ???

Yes. It should be trivial to write a script to automate this.
