SRV 记录请求的域名(即查询名称)具有严格定义的格式规范,遵循 DNS 协议标准(RFC 2782)。其核心格式结构如下:
⚙️ SRV 记录域名的标准格式
_
_
_
完整示例:_sip._tcp.example.com.
服务:_sip(SIP 通信服务)
协议:_tcp(TCP 协议)
域名:example.com.(根域名)[citation:1][citation:2][citation:5]。
🔍 关键组成部分详解
服务名称(_
前缀下划线:强制要求(如 _ldap、_kerberos),用于区分普通主机名。
常见服务:
服务类型
记录示例
用途
SIP 通信
_sip
VoIP 电话系统
LDAP 目录服务
_ldap
用户认证
HTTP 服务
_http
网页访问
XMPP 消息协议
_xmpp
即时通讯
协议类型(_
仅支持传输层协议:_tcp(可靠连接)或 _udp(无连接)。
示例:
_sip._tcp.example.com. → TCP 端口的 SIP 服务
_sip._udp.example.com. → UDP 端口的 SIP 服务 [citation:1][citation:3]。
域名主体(
完全限定域名(FQDN):必须包含根域结尾点(如 example.com.),避免解析歧义。
层级关系:域名可包含子域(如 _service._tcp.subdomain.example.com.)[citation:2][citation:4]。
💻 实际应用场景
1. 服务发现(如 SIP 通信)
客户端查询 _sip._tcp.example.com.,DNS 返回:
_sip._tcp.example.com. 3600 IN SRV 10 50 5060 sip-server1.example.com.
端口:5060(SIP 标准端口)
目标服务器:sip-server1.example.com.(需配套 A/AAAA 记录)[citation:5]。
2. 负载均衡与高可用
多条 SRV 记录通过 优先级(Priority) 和 权重(Weight) 实现流量分配:
_http._tcp.web.example.com. IN SRV 5 60 80 web1.example.com.
_http._tcp.web.example.com. IN SRV 10 40 80 web2.example.com.
客户端优先连接 web1(优先级 5 > 10),并按权重 60:40 分配请求 [citation:1][citation:2]。
3. Kubernetes 服务发现
无头服务(Headless Service)自动生成 SRV 记录,格式为:
_
示例:服务 my-svc 的命名端口 https 生成记录:
_https._tcp.my-svc.default.svc.cluster.local.
解析结果为关联 Pod 的 IP 和端口列表 [citation:4]。
⚠️ 配置注意事项
记录值格式:
SRV 记录值必须按顺序包含:
<优先级> <权重> <端口> <目标主机>
例如:0 10 5060 sip.example.com. [citation:3]。
依赖 A/AAAA 记录:
Target 字段的主机名(如 sip-server1.example.com.)必须存在 A 或 AAAA 记录,不可直接指向 CNAME [citation:2]。
TTL 设置:
较短的 TTL(如 300 秒)可快速更新配置,但增加 DNS 查询压力;较长的 TTL(如 86400 秒)适合稳定服务 [citation:3]。
💎 总结:SRV 域名格式核心要素
组件
格式要求
示例
作用
服务名称
_
_sip、_ldap
标识服务类型
协议类型
_
_tcp、_udp
指定传输协议
域名主体
example.com.
服务所属域名
完整格式
_
_http._tcp.web.example.com.
唯一确定服务端点
通过 dig SRV _sip._tcp.example.com 或 nslookup -type=SRV _http._tcp.example.com 可验证记录配置 [citation:2][citation:5]。
格式规范
SRV 记录(Service Record)是 DNS 中用于定位特定服务的资源记录类型,其标准格式为 _
🔧 一、_Proto(协议类型)
SRV 记录仅支持 两种传输层协议:
_tcp
用于基于 TCP 协议的服务(如 HTTP、SMTP 等)。
示例:_http._tcp.example.com.
_udp
用于基于 UDP 协议的服务(如 VoIP、DNS 等)。
示例:_sip._udp.example.com.
⚠️ 注意:协议类型必须以下划线 _ 开头,且仅支持 _tcp 或 _udp[citation:1][citation:3][citation:4][citation:5]。
🛠️ 二、_Service(服务类型)
服务类型需以下划线 _ 开头,以下为常见标准服务类型及场景:
服务类型
应用场景
示例记录格式
_http
HTTP 网页服务
_http._tcp.example.com.
_https
HTTPS 加密网页服务
_https._tcp.example.com.
_sip
VoIP 电话系统(SIP 协议)
_sip._tcp.example.com.
_smtp
邮件传输(SMTP 协议)
_smtp._tcp.example.com.
_imap
邮件接收(IMAP 协议)
_imap._tcp.example.com.
_ldap
目录服务(LDAP 协议)
_ldap._tcp.example.com.
_kerberos
认证服务(Kerberos 协议)
_kerberos._tcp.example.com.
_xmpp-server
即时通讯(XMPP 协议)
_xmpp-server._tcp.example.com.
_minecraft
Minecraft 游戏服务器
_minecraft._tcp.example.com.
_docker-server
Docker 容器服务
_docker-server._tcp.example.com.
💡 特殊场景扩展:
Kubernetes 服务发现:SRV 记录自动生成格式为 _
Active Directory:分组记录如 _MSDCS(域控制器)、_SITES(站点特定服务)[citation:4]。
⚠️ 三、配置注意事项
域名格式要求:
必须为 完全限定域名(FQDN),以点结尾(如 example.com.)[citation:1][citation:4]。
服务名和协议名均需包含前缀下划线(如 _http._tcp)。
记录值依赖:
Target 字段的主机名(如 sipserver.example.com.)必须存在 A/AAAA 记录,不可指向 CNAME[citation:4][citation:5]。
权重与优先级:
优先级(Priority):数值越小越优先(0-65535)。
权重(Weight):同优先级时按权重分配流量(0-65535)[citation:1][citation:3]。
💎 四、总结
_Proto 类型:仅 _tcp 和 _udp。
_Service 类型:灵活自定义,需以下划线开头(如 _http、_sip),支持主流网络服务及私有协议。
实际配置:# SIP 服务示例
_sip._tcp.example.com. 3600 IN SRV 10 50 5060 sipserver.example.com.
可通过 dig SRV _http._tcp.example.com 或 nslookup -type=SRV _sip._udp.example.com 验证记录[citation:3][citation:4]。