Setting up DNS SRV for services like SIP and IAX…

This is a copy and paste from voip-info.org which helped me on a recent project… All credits go to the author of the post oej…

DNS SRV

A Domain Name Server (DNS) SRV record helps connecting to a SIP user in a similar way that an MX record helps email delivery. When you send email to “john@example.com”, the MX record for example.com might tell the mail transfer agent to deliver email to a completely different machine, such as “zaphod.foobar.com”. Similarly, when you want to make a SIP phone call to john@example.com, the SRV record might tell your computer that it should connect to “galaxy.starsystem.tw” to do so.

Why use DNS SRV records for SIP?
Dialling by domain names lets a SIP user have a single public “SIP address” which can be redirected at will to their current location. SRV records maintain stability and also opens up the possibility to use your own domain, regardless of the domain of the SIP service you are using.

DNS SRV resource records indicates how to find services for various protocols.

From the RFC:This document describes a DNS RR which specifies the location of the server(s) for a specific protocol and domain.

Currently, one must either know the exact address of a server to contact it, or broadcast a question.

The SRV RR allows administrators to use several servers for a single domain, to move services from host to host with little fuss, and to designate some hosts as primary servers for a service and others as backups.

Clients ask for a specific service/protocol for a specific domain (the word domain is used here in the strict RFC 1034 sense), and get back the names of any available servers.
For a SIP proxy in a domain, this means that

You can set SRV records of a domain to point to a SIP proxy in another domain. Like e-mail, where a mail server handles mail to many domains, a SIP proxy can handle users in many domains. The key is to set the DNS SRV records in the user domain (like voip-info.org) zone file to point to a SIP Proxy somewhere else (like sip.iptel.org). With a configuration like this, calls to user@voip-info.org will be automatically routed to the SIP proxy sip.iptel.org.

In a DNS zone, you can specify multiple SIP proxies. If the proxy with the highest priority is not reachable, the SIP ua or proxy that tries to reach a user within the domain tries the next proxy defined in the zone with a SRV record.

Example

In order to use SRV records, you will need the following information:

a. The IETF Service Type (You can view a more or less complete listing of those here, original RFC #2782 here) in the format _servicetype._layer4.
b. The priority of your systems.
c. The load, or ‘weight’ those systems can handle. (optional)
d. The port number your service will be running on.
e. The hostname of the system your service will run on.

All of this information gets entered into your zone file in the above order, like so:

a (TTL) SRV b (c) d e.

For example, you would do a sip server, running on host.tld like so:

_sip._udp SRV 0 5060 host.tld.

As I described above, _sip._udp is the IETF Service Type for SIP protocol running on UDP. SRV is the DNS record type, 0 is the priority of this entry, we don’t have a load entry here, and
5060 is the port number that SIP runs on. host.tld is our hostname.

You could do a similar setup for iax, like so:

_iax._udp SRV 0 4569 host.tld.

You will of course need to make sure that host.tld has a related A record or CNAME record to go with it, like so:

host.tld A xxx.xxx.xxx.xxx

There is an extensive document with a very detailed example at Cisco’s webite:

Here’s the sample zone file from the RFC. Note the SRV they are defining is *not* for SIP, so it’ll be different for you:

Fictional example

This example uses fictional service “foobar”, running on port 9 as an aid in
understanding SRV records. If ever service “foobar” is implemented,
it is not intended that it will necessarily use SRV records. This is
(part of) the zone file for example.com, a still-unused domain: