SRV Record

A DNS Service (SRV) record is a specification that defines the location - including the hostname and port number - of servers for specified services. Unlike most DNS records that only provide a server name or IP address, SRV records include both the target server and the specific port where the service is running, along with priority and weight values for load balancing and failover.

How it works

SRV records allow applications to discover services in a domain without requiring manual configuration. They're commonly used for services that need to advertise specific ports, such as VoIP, instant messaging (XMPP), email (SMTP), and directory services (LDAP). By querying SRV records, clients can automatically find the correct server and port for a service.

SRV records contain four key values that control service routing and load balancing: **Record Format:** SRV records follow the format: _service._proto.name - _service: The symbolic name of the service (e.g., _xmpp, _sip, _ldap) - _proto: The transport protocol (usually _tcp or _udp) - name: The domain name Example: _xmpp._tcp.example.com **Priority (Lower = Higher Priority):** Clients should contact servers with the lowest priority value first. If that server is unavailable, they fall back to servers with higher priority values. For example, if you have servers with priorities 10, 20, and 30, the server with priority 10 is always tried first, regardless of weight values. **Weight (Load Balancing):** When multiple servers have the same priority, weight determines the proportion of traffic each should receive. Weights are relative values - if three servers with equal priority have weights of 60, 30, and 10 (totaling 100), they'll receive approximately 60%, 30%, and 10% of requests respectively. **Port:** The TCP or UDP port number where the service is running on the target server. This is what makes SRV records unique - they specify both the host and the exact port. **Target:** The hostname of the server providing the service. This must be an A or AAAA record (not a CNAME).

Key Points

  • SRV records include both hostname and port number, unlike other DNS records
  • Format is _service._proto.name (e.g., _xmpp._tcp.example.com)
  • Priority determines order of contact (lower numbers first), weight determines load distribution among equal priorities
  • Commonly used for VoIP, instant messaging, email, and directory services
  • The target must point to a hostname with an A or AAAA record, not a CNAME

Common Use Cases

  • VoIP and SIP Services: SIP (Session Initiation Protocol) uses SRV records to locate VoIP servers, allowing clients to discover the correct server and port for voice calls automatically
  • Instant Messaging (XMPP/Jabber): XMPP services use SRV records to enable federated messaging, allowing servers to discover and connect to other XMPP servers
  • Microsoft Active Directory: Active Directory uses SRV records extensively for service discovery, allowing clients to find domain controllers, LDAP servers, and Kerberos services
  • Email Submission: The _submission._tcp SRV record can specify the mail submission service port, complementing MX records for email configuration

code Example SRV Record Configuration

TypeHost / NameValue / Points toTTL
SRV_xmpp._tcp10 60 5222 server1.example.com3600
SRV_xmpp._tcp10 40 5222 server2.example.com3600
SRV_xmpp._tcp20 0 5222 backup.example.com3600
SRV_sip._tcp10 0 5060 voip.example.com3600

* SRV records specify service, protocol, priority, weight, port, and target. Lower priority = higher preference.

Frequently Asked Questions

What is the difference between priority and weight in SRV records?expand_more
Priority determines which servers are contacted first - clients always try the lowest priority value first. Weight only matters among servers with the same priority and determines what proportion of traffic each should receive. For example, if Server A has priority 10 and Servers B and C have priority 20, Server A is always tried first regardless of any weight values. Only if Server A is unavailable will weight come into play for choosing between B and C.
Why can't the target be a CNAME?expand_more
According to DNS specifications (RFC 2782), the target of an SRV record must be a hostname with an A or AAAA record, not a CNAME. This is because allowing CNAMEs would create additional lookup complexity and potential circular dependencies. If you need to point to a different hostname, create an A record for your target hostname first, then point your SRV record to that A record.
Do I need SRV records for my website?expand_more
No, standard websites don't use SRV records - they use A records or CNAME records. SRV records are for specific services that need to advertise both a hostname and a port number, such as VoIP (SIP), instant messaging (XMPP), email submission, or directory services (LDAP). If you're just hosting a website, you only need A/AAAA records and possibly CNAME records.
How do applications know to look for SRV records?expand_more
Applications that support SRV records are specifically programmed to query for them. For example, an XMPP client configured for user@example.com will automatically query for _xmpp-client._tcp.example.com SRV records to find the messaging server. The application knows the service name and protocol to look for based on its function. Not all applications support SRV records - support must be explicitly built into the software.
Can I use SRV records for HTTP/HTTPS services?expand_more
While technically possible, SRV records are not commonly used for HTTP/HTTPS because web browsers don't query SRV records by default. Browsers expect websites to be accessible on standard ports (80 for HTTP, 443 for HTTPS) at the hostname in the URL. SRV records are best suited for services where the client application is designed to query them, like VoIP clients, messaging clients, or enterprise software.