Understanding DNS SRV records and SIP

What are SRV records?
DNS SRV records or service records are a type of DNS entry that specify information on a service available in a domain. They are typically used by clients who want to know the location of a service within a domain. For example, in an Active Directory environment, domain joined windows PCs rely on SRV records to locate domain controllers to authenticate to within their domain.
A SRV record record contains the following information:
  • Service Name: the well know name of the service
  • Protocol: specifies if this is a TCP or UDP service
  • Domain Name: the domain name that this record belongs to
  • TTL: Time to Live value
  • Class: DNS class field. This always has the value of "IN"
  • Priority: when multiple hosts are configured for the same service, the priority determines which host is tried first
  • Weight: A relative weight for records with the same priority
  • Port: the TCP or UDP port that the service uses
  • Target: the name of the host providing the service
Here is an example of a SRV record, that specifies that a SIP/UDP server, with a priority of 10, can be contacted at asterisk.lithnet.local, on port 5060.
_sip._udp.lithnet.local. 86400 IN SRV 10 5 5060 asterisk.lithnet.local.
SIP and the SRV record
SIP clients use SRV lookups to determine where to send an outgoing call. Configuring a DNS SRV records means that you can use your domain name rather than the full host name of the server in the SIP address you give to people. For example, without SRV records, people can only call me on 400@asterisk.lithnet.local. If I configure the SRV record shown in the example above, I can drop the hostname, and people can call me on 400@lithnet.local.
How does a SIP client use SRV records?
If I try to call 400@asterisk.lithnet.local, my SIP client will first perform a DNS SRV lookup. It will query its DNS server for the records:
_sip._udp.asterisk.lithnet.local and
_sip._tcp.asterisk.lithnet.local
If I have either of them configured in my DNS, my SIP client will forward the call to the host and port number specified in the DNS response. If I do not have them configured, the SIP client will try to contact asterisk.lithnet.local directly (by assuming it is a hostname) on the well known SIP port (5060).
An SRV record can also be used to redirect a SIP client to a different server. If I retire my asterisk.lithnet.local, and replace it with newserver.lithnet.local, I can create a SRV record so that calls directed to @asterisk.lithnet.local are forwarded to the new server.
_sip._udp.asterisk.lithnet.local. 86400 IN SRV 10 5 5060 newserver.lithnet.local.
I might also want to direct calls to a non standard port on my asterisk server. I can do this without having to configure the clients at all.
_sip._udp.asterisk.lithnet.local. 86400 IN SRV 10 5 5070 asterisk.lithnet.local.
Correctly configured, SRV records make managing SIP domains a lot easier.
Sounds great... So how do I do?
From a Windows server with the DNS server installed, open the DNS Management MMC. Right click the domain (or subdomain) you are assigning this service to, and select "Other New Records..."

Scroll down to Service Location (SRV) in the list. Type _sip in the service field, select _udp from the protocol field, assign a priority and weight, enter 5060 as the port number, and the host name of your SIP server.

Click OK and you are done. You can view your new SRV record by clicking on the _udp item under your domain. In the example here, I would now be able to receive calls to @lithnet.local extensions, as well as @asterisk.lithnet.local.

Comments

Anonymous said…
Thank you!
Anonymous said…
gud example I shld say
Anonymous said…
there is a good example selection in this blog hence a gud understanding in brief
Anonymous said…
hai its really helpfull.. thank you
Anonymous said…
Clear, conscise, real world. Enough background without too much fluff.
Anonymous said…
thanks alot you just saved my life
tyvm*100
Anonymous said…
Thanks a lot!
Anonymous said…
Command line examples to look up a SRV record:

dig @google-public-dns-a.google.com _sip._udp.example.com srv
host -t srv _sip._udp.example.com
nslookup -type=srv _sip._udp.example.com
Anonymous said…
Very good explanation. Thanks