Using Consul DNS Interface

29/12/2020
DNS
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 service.us-east .It is important to configure some details like client_addr, ports.DNS, recursors, domain, and, dns_config.

Prerequisite

  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.

prome.node.dc1.consul

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.

 prome.node.consul

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.

prome.service.consul

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.

primary.mariadb.service.dc5.consul

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:

search YourDomain.com
nameserver 127.0.0.1

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

Next, your consul agent configuration should look like this:

{
"datacenter": "dc1",
"data_dir": "/var/consul",
"recursors" : [ "8.8.8.8" ],
"ports" : {
"dns" : 53
},
"retry_join": [ "35.75.10.85""35.75.10.111", "35.75.10.123" ]
}

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.

Conclusion

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

How to use Nslookup in Debian

Nslookup or name server lookup is a tool used by network administrators to find the hostname, IP address or other DNS records...
29/12/2020

What is DNS and how does it work

This tutorial aims to explain, in the simplest way, what DNS (the Domain Name System) is and how it works. This article...
29/12/2020

Premium DNS services

Premium DNS Extremely quick websites always give a good impression to the visitors. The difference between the lookup speed...
28/12/2020
Bài Viết

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

SỰ KHÁC BIỆT GIỮA RESIDENTIAL PROXY VÀ PROXY DATACENTER
17/02/2024

Mua Proxy v6 US Private chạy PRE, Face, Insta, Gmail
07/01/2024

Mua shadowsocks và hướng dẫn sữ dụng trên window
05/01/2024

Tại sao Proxy Socks lại được ưa chuộng hơn Proxy HTTP?
04/01/2024

Mua thuê proxy v4 nuôi zalo chất lượng cao, kinh nghiệm tránh quét tài khoản zalo
02/01/2024