In this tutorial, we’ll discuss various types of DNS records. Finally, we’ll discuss how to redirect DNS records to different ports.
2. Introduction to DNS
In computer networks, we can identify a device using an IP address. On the other hand, human beings find it easy to use word-based addresses. Therefore, we can easily remember domain names like google.com. However, remembering an IP address 22.214.171.124 is difficult.
Therefore, there’s a need to keep a directory that maps these domain names to their server IP addresses. A domain name system (DNS) acts like a telephone directory for the domain names. Additionally, it provides the IP address of the server for a particular domain name. A server address has two parts: IP address and port number.
To find the IP address for a domain name, a device searches the DNS record in local cache memory. Therefore, the request goes to the resolver ISP cache server if the entry is not found. Additionally, if we still can’t find the record in the ISP cache, a root server is given the task of fetching the IP address for the domain. It helps resolve the IP address using the top-level domain (TLD) and name servers.
DNS records are the records which map domain name information to IP addresses. A DNS record is not limited to an IP address but also contains several other information. Common DNS record types are A, CNAME, Mx, SPF, Txt, DKIM, NS, CAA, and SRV records.
We use a canonical name record (CNAME) to map one domain or subdomain name to another domain. A mail exchanger record (MxRecord) is a record of the mail server for a domain name. For example, if a domain name has a different mail server other than the server provided by the host, DNS information can be provided via MxRecord. SPF and DKIM records are important for the mail servers. Additionally, they help in email security aspects, including authentication and preventing email spoofing.
3. SRV Record
In order to redirect DNS to different ports, a service record (SRV) plays an important role. An SRV record is a type of DNS record that contains information about the location of a particular service. Additionally, the SRV record contains the server address to connect to that service.
Different services like SMTP, VoIP, and instant messaging can be configured using the SRV record. Furthermore, an SRV record includes IP address, port, and time to live (TTL). Let’s discuss all the fields of an SRV record:
The name field in an SRV record denotes the domain name and must end with a dot. Service displays the short form of the desired service. The protocol field provides information on the specific protocol used in the service. In general, the most popular protocols are TCP and UDP. Time to live (TTL) denotes the time we want to keep the DNS record in the cache memory. Hence, the changes in DNS records are reflected after the exceed of TTL.
Priority is a number representing priority given to a host. A lower value denotes a higher priority. Let’s assume there’re two servers, A and B. Therefore, if server A has a lower priority value than server B, the request traffic will always go to server A.
The weight field represents the weight given to hosts. Given the same priority, if the weight of a particular host is higher, it has a greater chance of being selected for the incoming traffic. Additionally, if two servers have the same priority value, the request traffic will be divided among servers. Therefore, the server with the highest priority value and a higher weight receives a relatively higher number of requests.
The port represents the type of port available for the servers to connect. In general, a port is either a TCP or a UDP port. Finally, the field target denotes the hostname of the machine which provides some particular services. Additionally, there are two more fields: IN, which indicates a DNS class, and SRV represents the type of the record.
Now let’s take a look at the general stand form of an SRV record:
_Service._Protocol.Name. TTL IN SRV Priority Weight Port Target.
Some examples of the SRV records are:
_testservice._tcp.example.com. 18000 IN SRV 10 40 5555 tar1.example.com.
4. Redirecting DNS to Different Ports
Now let’s talk about an application of SRV record. We want to solve the problem of connecting different subdomains of a domain to different servers or ports:
Suppose we want to connect multiple subdomains of a domain example.com to the different ports of an IP address:
Multiple servers running on the same public IP address are exposed through different ports. Additionally, we want to assign three different subdomains to different ports. Therefore, in this way, we can ensure that the requests for different subdomains go to their respective servers. Hence, this can be achieved by creating SRV records. For a subdomain, we can create a service record (SRV):
_xyzservice._tcp.example.com. 18000 IN SRV 10 40 5555 sub1.example.com. _xyzservice._tcp.example.com. 18000 IN SRV 10 30 5556 sub2.example.com. _xyzservice._tcp.example.com. 18000 IN SRV 10 30 5557 sub3.example.com.
Therefore, different requests for different subdomains will go to different ports of the public IP address. If different servers are exposed through different ports, requests for a particular subdomain will go to its corresponding server. Additionally, SRV records mentioned above need A record to specify the IP address of the particular server. Hence, let’s look at the A record entries:
sub1.example.com. 18000 IN A <IP Address> sub2.example.com. 18000 IN A <IP Address> sub3.example.com. 18000 IN A <IP Address>
In this way, SRV records can redirect DNS addresses by dividing different subdomain requests to different physical servers or ports.
In this tutorial, we discuss several types of DNS records. We explored the SRV record in detail. Finally, we explained how SRV records could help to redirect DNS to different ports.