Using Consul DNS Interface

The DNS interface of Consul will help you to achieve service discovery without any personal-touch integration with the consul. The default port for listening a DNS server in consul agent is port 8600. Generally, we make a HTTP API request for name lookup but here we can use the DNS server directly like .It is important to configure some details like client_addr, ports.DNS, recursors, domain, and, dns_config.


  1. A Virtual Server instance
  2. Consul installed on the server
  3. A root user

Update System

We recommend you to upgrade all the available packages and repositories before performing any new operation. Execute the following command and it will do the job for you. On Linux

apt-get update
On RHEL/CentOS yum -y update

Node Lookups

You can query any DNS records such as host addresses, mail exchanges, and name servers on the command line by using dig tool. You can retrieve the address of any node by making a simple query. <node>.node[.datacenter].<domain> Suppose there is a node running named prome in the datacenter dc1 then you can look for that node using the following command.


If in case the node is running in the same datacenter as consul agent then you don’t need to specify the datacenter. you can look for that node using the following command.


Service Lookups

Service lookup is a query to get information about the service provider. The format of standard service lookup is as follows: [tag.]<service>.service[.datacenter].<domain> tag is completely optional in the above command. Suppose you want to lookup for a service named prome in the local datacenter then you don’t need to specify the datacenter also.


You can also use the tag to filter the results of a query. Suppose, you wish to find the MariaDB primary in a specific datacenter then use the following command.


Using Consul DNS

In this guide, we will see different ways to use the consul DNS interface. There are mainly 3 ways to use Consul DNS: 1. Employ a custom DNS resolver library 2. Appoint Consul as the DNS server for a instance 3. Forward Queries for Consul TLD From a DNS Server

Employ a custom DNS resolver library

One way of using consul DNS interface is to use a DNS resolver library for your language of choice and your code will query the interface directly. Apply custom logic to your code otherwise, you’ll be limited to IP address of the service. Otherwise, if you use a DNS interface then you will need to run the service on a specific port and your client should also know that port to access it.

Appoint Consul as the DNS server for a instance

You can use the consul DNS server for a node by configuring the host to deliver DNS queries directly to the local Consul agent’s DNS server. To do so, you will need to modify both the system and the Consul agent configuration.

First, you will have to change the system configuration. You will need to modify the resolv.conf file on the system using any text editor. Here we are using nano text editor.

nano resolv.conf

The file should look like this:


Please don’t forget to replace with your actual domain.

Next, your consul agent configuration should look like this:

"datacenter": "dc1",
"data_dir": "/var/consul",
"recursors" : [ "" ],
"ports" : {
"dns" : 53
"retry_join": [ """", "" ]

The Consul agent will continue to be able to deal with records for records outside of the consul TLD even if the server cluster is down or unavailable.

Forward Queries for Consul TLD From a DNS Server

You can use consul DNS to forward all the queries to consul agent from existing DNS server. We recommend you to use various BIND servers and run consul agent locally on all the BIND servers. So that whenever a query is accepted by a BIND server then it will be automatically shipped to its consul DNS server.


In this guide, you have learned using the Consul DNS interface in your consul cluster. You have also learned using the type of queries like Node lookup and service lookup.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

DnsCrypt on Ubuntu – Encrypted DNS Traffic

DNSCrypt is an authentication protocol that facilitates the communication between DNS clients and DNS resolvers.  It’s...

Using Consul DNS Interface

The DNS interface of Consul will help you to achieve service discovery without any personal-touch integration with the...

How to Install and Use DIG on Debian 9

The full form of DIG is Domain Information Groper. It is a command line utility for network administrators.The domain name...
Bài Viết

Bài Viết Mới Cập Nhật

Check proxy trên trang nào chuẩn nhất❓

Thuê Proxy chạy Google Ads / Cần chú ý gì khi chọn proxy và email chạy G.G ads?

Thuê proxy 4G ở đâu uy tín, giá rẻ, chất lượng?

Vì sao cần thuê proxy xoay? Địa chỉ cung cấp proxy xoay uy tín

Thuê proxy v6 kéo view Youtube ở đâu uy tín, chất lượng?