SRV Records and Service Discovery
Learn how SRV records tell software which host and port offer a service, how priority and weight work and where they apply.
Key takeaways
- An SRV record names a service and protocol, then gives priority, weight, port and target host.
- Clients try the lowest priority number first and use weight to share load among equals.
- The target must be a hostname with address records, and a lone dot means the service is not offered.
- Only protocols and applications designed to look up SRV records will benefit from publishing them.
An SRV record answers a more detailed question than an address record. Instead of "what is the address of this name?", software asks "where is the service of this kind for this domain?" and gets back a hostname, a port number and instructions for choosing among several servers.
That lets a user type only a domain or an email address while the application finds the right machine on its own. The catch is that SRV works only when the software has been written to ask for it. Web browsers, notably, do not use SRV records to find websites.
The format
The record's name is built from parts:
_service._proto.name. TTL IN SRV priority weight port target. A concrete example for a chat service:
_xmpp-client._tcp.example.com. 3600 IN SRV 10 60 5222 chat1.example.com.
_xmpp-client._tcp.example.com. 3600 IN SRV 10 40 5222 chat2.example.com.
_xmpp-client._tcp.example.com. 3600 IN SRV 20 0 5222 backup.example.net. The underscores keep service labels from colliding with ordinary hostnames. The format is defined in RFC 2782.
Priority and weight
These two numbers are what make SRV more than a signpost.
Priority forms tiers. A client uses servers in the lowest-numbered tier and moves to the next only if none in that tier can be reached.
Weight divides traffic within a tier. In the example, chat1 and chat2 share priority 10, so clients should pick chat1 about 60 percent of the time and chat2 about 40 percent. Weights are proportions, so 3 and 2 would mean the same thing. Use 0 when there is nothing to balance.
DNS does no health checking here. It hands out the list, and the client decides when a server has failed. Cached answers also mean that weight changes take effect gradually, following the TTL.
Where you meet SRV records
| Area | Example record name | Used to find |
|---|---|---|
| Directory services | _ldap._tcp.example.com | Directory servers |
| Authentication | _kerberos._tcp.example.com | Kerberos key servers |
| Voice calls | _sip._udp.example.com | SIP servers |
| Chat | _xmpp-client._tcp.example.com | XMPP servers |
| Mail setup | _imaps._tcp.example.com | Mail access servers, where clients support it |
| Calendars | _caldavs._tcp.example.com | Calendar servers |
| Games | _minecraft._tcp.example.com | A game server on a custom port |
The most important everyday case is in business networks. Windows Active Directory depends heavily on SRV records to locate domain controllers. If a computer cannot join or sign in to a domain, a frequent cause is that it is using a DNS server that does not hold those internal records. That ties into split-horizon DNS.
Hosted office and communication suites sometimes ask you to add SRV records during setup. Add them exactly as given, and remove them if you leave the service.
Entering one in a DNS dashboard
Dashboards vary. Some take the whole name in one field, such as _sip._tcp. Others have separate boxes for service and protocol. Then there are fields for priority, weight, port and target.
Watch for these mistakes:
- Leaving the underscore off the service or protocol.
- Letting the domain be appended twice to the name.
- Putting an IP address or a URL in the target.
- Pointing the target at a CNAME; it should have address records of its own.
- Swapping priority, weight and port.
To say clearly that a service is not available at a domain, publish a record with the target set to a single dot:
_sip._tcp.example.com. 3600 IN SRV 0 0 0 . Looking them up
You must ask for the full service name; querying the domain alone will not list SRV records.
dig _xmpp-client._tcp.example.com SRV +short Resolve-DnsName _ldap._tcp.example.com -Type SRV nslookup -type=srv _sip._tcp.example.com Then test the port on the target, for a service you run or are entitled to use:
Test-NetConnection chat1.example.com -Port 5222 A worked example: planning priority and weight
Say you run a voice service with two servers in your main site and one at a recovery site. The larger of the main servers should take about three quarters of the calls.
_sip._tcp.example.com. 300 IN SRV 10 75 5060 sip-a.example.com.
_sip._tcp.example.com. 300 IN SRV 10 25 5060 sip-b.example.com.
_sip._tcp.example.com. 300 IN SRV 20 0 5060 sip-dr.example.com.
sip-a.example.com. 300 IN A 192.0.2.31
sip-b.example.com. 300 IN A 192.0.2.32
sip-dr.example.com. 300 IN A 203.0.113.31 In normal operation, new connections split between sip-a and sip-b in roughly a three to one ratio. Because the choice is random per client, the split is approximate, and a handful of clients may not divide neatly at all. If both main servers stop answering, clients move to sip-dr.
To drain sip-a for maintenance, remove its record or raise its priority number, then wait for the TTL to pass before shutting it down. A short TTL such as 300 seconds makes that wait tolerable. Check how your particular clients behave, since some resolve once when they start and do not look again until restarted.
When SRV is the right tool
SRV fits well when you control or know the client software and it already supports the lookup. It lets you change ports and hosts centrally, build simple primary and standby arrangements and avoid asking users to type server names.
It fits poorly when clients ignore it, when you need instant failover or when traffic must be balanced precisely. In those cases a stable hostname in front of a load balancer is easier to reason about. It is also not a firewall rule: publishing port 5222 in DNS does not open that port anywhere. You still have to permit the traffic and make sure the service is listening.
Service discovery on a local network
SRV records also underpin a way of finding devices with no configuration at all. DNS-based service discovery combines them with PTR records, which list the available instances of a service, and TXT records, which add details. On a home or office network it usually runs over multicast DNS, which sends queries to neighboring devices instead of a central server and uses names ending in .local.
This is how a laptop can show a nearby printer or media receiver without anyone typing an address. Because multicast normally stays within one network segment, a phone on a guest network often cannot see the printer on the main one. That is expected behavior, and crossing segments needs a deliberate relay.
Service discovery inside larger systems
The same idea, "ask by service name and get current locations", appears in data centers and container platforms. Some publish SRV records from an internal DNS server so that applications can find instances that start and stop frequently. Others use their own registry, a proxy or a load balancer with one stable name.
DNS discovery is simple and widely supported by libraries, but cached answers lag behind fast changes, and not every client honors TTLs. Where instances change by the second, systems usually add health checks and a proxy layer.
SRV and the web
Browsers connect to a website using the name in the address and a default or stated port. They ignore SRV. The web's counterpart is the newer HTTPS record, which can point to alternative endpoints and advertise protocol support; see SVCB and HTTPS records. If you need a website on an unusual port, put the port in the URL or place a reverse proxy on the standard one.
Security notes
Public SRV records tell anyone which services you offer and where. Publish only what outside users need, and keep internal service records on internal DNS. A client should also verify that the server it reaches presents credentials valid for the domain it asked about, since plain DNS answers can be tampered with. DNSSEC lets validating resolvers detect altered records, and firewalls and authentication still protect the service itself.
Reading an unfamiliar SRV record
When you find SRV records in a zone you did not build, work out their purpose before touching them. The service label usually names the protocol, and the port is a second clue. The target tells you whether it points at one of your own machines or at an outside provider. Compare that with your list of services in use. A record aimed at a platform you left long ago is safe to retire once you have confirmed nobody depends on it, while one under an internal directory zone is often maintained automatically by the servers themselves. Deleting those by hand can break sign-in until they are registered again.
Troubleshooting
- Query the exact record name against the DNS server the client uses.
- Confirm that each target resolves to an address.
- Check that the port in the record matches what the server listens on.
- Test the connection through any firewall between client and server.
- Verify that the application really uses SRV; its documentation will say. If it does not, enter the server and port in its settings instead.