文档目录

SRV记录

定义

SRV 记录(Service Record,服务记录)是一种 DNS 记录类型,用于指定特定服务的主机和端口号。SRV 记录通常用于自动发现服务,如 SIP(Session Initiation Protocol)、XMPP(Extensible Messaging and Presence Protocol)等协议的服务发现。


用途


格式

SRV记录的基本格式如下:

《
  类型=srv
  名=_服务名._协议.域名
  优先级=<优先级>
  权重=<权重>
  端口=<端口号>
  主机域名=<主机域名>
  【生存时间=<生存时间>】  # 可选,单位通常是秒,默认值由DNS服务器配置决定
  【注释=<注释信息>】  # 可选,用于记录额外的说明信息
》

示例

假设我们需要为域名example.com配置一个SIP服务的SRV记录,指定两台服务器sip1.example.comsip2.example.com,其中sip1.example.com优先级更高且权重更大,可以这样写:

《
  类型=srv
  名=_sip._tcp.example.com
  优先级=10
  权重=60
  端口=5060
  主机域名=sip1.example.com
  生存时间=3600
  注释=SIP服务主服务器
》

《
  类型=srv
  名=_sip._tcp.example.com
  优先级=20
  权重=40
  端口=5060
  主机域名=sip2.example.com
  生存时间=3600
  注释=SIP服务备用服务器
》

假设我们需要为域名example.com配置一个XMPP服务的SRV记录,指定一台服务器xmpp.example.com,可以这样写:

《
  类型=srv
  名=_xmpp-client._tcp.example.com
  优先级=0
  权重=10
  端口=5222
  主机域名=xmpp.example.com
  生存时间=3600
  注释=XMPP客户端服务
》

假设我们需要为域名example.com配置一个FTP服务的SRV记录,指定一台服务器ftp.example.com,可以这样写:

《
  类型=srv
  名=_ftp._tcp.example.com
  优先级=20
  权重=5
  端口=21
  主机域名=ftp.example.com
  生存时间=3600
  注释=FTP服务
》

注意事项


测试:

在 Terminal 执行:
nslookup -type=srv _sip._tcp.example.com 127.0.0.1
输出:

Server:		127.0.0.1
Address:	127.0.0.1#53

_sip._tcp.example.com	service = 10 60 5060 sip1.example.com.
_sip._tcp.example.com	service = 20 40 5060 sip2.example.com.