The DNS record of type SRV is used for special services.
What is a DNS SRV record?
The SRV record (Service Resource Record) allows determining and indicating which services are offered and available for a given domain (or subdomain), and to find the host providing a service (for example instant messaging with XMPP), by only knowing the delegated domain name, for example example.org or apple.example.
SRV records are often used for XMPP, SIP or LDAP protocols, as well as for the use of Office 365, for example.
The SRV record specifies a host and a port for specific services, such as instant messaging, or VoIP (Voice over IP), etc. Most other DNS records specify only a host (server) or an IP address, whereas SRV records also include a port associated with that IP address. Some Internet protocols notably require the use of SRV records to function.
What is the format of an SRV record?
Typical format of an SRV record:
_service._proto.name. TTL Class Record Type Priority Weight Port Target.
Here is an example of an SRV record:
_sip._tcp.example.com. 86400 IN SRV 0 10 5060 sipserver.example.com.
In the example above, “_sip” indicates the type of service concerned by this SRV record (the SIP protocol) and “_tcp” indicates the TCP transport protocol: it is a SIP connection on TCP port number 5060 (the SIP protocol always uses the assigned port 5060).
The expression “example.com” refers to the host (domain name), “sipserver.example.com” is the target server, and “5060” indicates the port on this server.
SRV records must necessarily point to an A record (IPv4) or an AAAA record (IPv6). The name of the pointing server cannot be a CNAME. So here the target server “sipserver.example.com” must point directly to an A or AAAA record under the domain name example.com.
What information does an SRV record contain?
An SRV record contains the following information:
| service | SIP |
| proto | TCP |
| name | example.com |
| TTL | 86400 |
| class | IN |
| type | SRV |
| priority | 0 |
| weight | 10 |
| port | 5060 |
| target | sipserver.example.com |
Service: The symbolic name (usually starting with an underscore _ (underscore)) of the concerned service (for example _sip).
Proto: Abbreviation of “Protocol”, usually it is either “_tcp” for the TCP protocol, or “_udp” for UDP.
Name: Domain name of the record’s validity (FQDN or local to the current DNS zone being defined for the same origin authority).
TTL: Standard DNS field indicating the record’s validity duration (Time-To-Live, or lifetime, in seconds).
Class: Standard DNS field indicating the addressing class (always IN for Internet).
Type: DNS record type (here always SRV for a service record).
Priority: The priority of the record or target server (non-negative integer value; the lower the value, the higher the priority level of the record – 0 being the highest priority). The record with the highest priority level is given precedence. If there are multiple SRV records with different priorities for the same service and protocol, only one record for each priority will be returned in response to recursive DNS servers or DNS clients: clients will preferentially connect to the server with the lowest priority value among the returned records, but if that fails, they can then use the next higher priority server in the list of servers returned to them, and so on. The different priorities allow setting up backup services.
Weight: The weight of the record; if two records have the same priority, the record with the higher weight is preferred. Relative weight for records of the same priority: integer value from 0 to 65535; allows authoritative DNS servers to randomly return one of the target servers with the same priority, according to a distribution corresponding to the indicated weight, relative to the total weight of the other records of the same priority (for the same service). The indicated weight has no importance or consequence if there is only one target server, or if there are multiple target servers with different priorities, for the same service and protocol.
Port: The port number (TCP or UDP depending on the above protocol) where the service is available. This is a network connection port. In networking, ports are virtual locations that designate the processes to which network traffic is destined on a machine. Ports notably allow machines to easily differentiate between different types of traffic. Like IP addresses, a number is assigned to each port.
Target: The name of the server providing the concerned service: must be resolved into an IPv4 or IPv6 address by other DNS queries on the A or AAAA records of the target service name, with the desired protocol and on the indicated port.
How to use priority and weight in an SRV record?
Priority and weight are used together to alternatively and/or simultaneously provide load balancing and a backup service.
In the example below, both the priority and weight fields are used to simultaneously provide load balancing and a backup service.
_sip._tcp.example.com. 86400 IN SRV 10 60 5060 mainserver.example.com. _sip._tcp.example.com. 86400 IN SRV 10 20 5060 secondaryserver1.example.com. _sip._tcp.example.com. 86400 IN SRV 10 20 5060 secondaryserver2.example.com. _sip._tcp.example.com. 86400 IN SRV 20 100 5060 backupserver.example.com.
The first three records all have the same priority of 10. Therefore, clients will have to use the weight field to determine which server should be contacted preferentially; for this field, the sum of the three values is 100, so “mainserver.example.com” will be used 60% of the time, and the other two “secondaryserver1.example.com” and “secondaryserver2.example.com” will be used randomly 20% of the time each. In the event that the first server “mainserver.example.com” is unavailable, the two other “secondary servers” would then share the load equally, since they have identical weight.
Furthermore, if these 3 servers of priority 10 were simultaneously unavailable, the record with the next higher priority would then be chosen, in our example “backupserver.example.com” with priority 20.
Learn more:
RFC 2782: A DNS RR for specifying the location of services (DNS SRV)
RFC 6186: Use of SRV Records for Locating Email Submission/Access services