SRV域名介绍
SRV 记录请求的域名(即查询名称)具有严格定义的格式规范,遵循 DNS 协议标准(RFC 2782)。其核心格式结构如下:
⚙️ SRV 记录域名的标准格式
_<service>._<proto>.<domain>
_<service>:服务名称,必须以_开头,表示特定服务类型(如_sip、_http)。_<proto>:协议类型,必须以_开头,通常为_tcp或_udp。<domain>:域名主体,即服务所属的域名(如example.com),需以.结尾(表示完全限定域名 FQDN)。
完整示例:_sip._tcp.example.com.
- 服务:
_sip(SIP 通信服务) - 协议:
_tcp(TCP 协议) - 域名:
example.com.(根域名)[citation:1][citation:2][citation:5]。
🔍 关键组成部分详解
-
服务名称(
_<service>)- 前缀下划线:强制要求(如
_ldap、_kerberos),用于区分普通主机名。 - 常见服务:
服务类型 记录示例 用途 SIP 通信 _sipVoIP 电话系统 LDAP 目录服务 _ldap用户认证 HTTP 服务 _http网页访问 XMPP 消息协议 _xmpp即时通讯
- 前缀下划线:强制要求(如
-
协议类型(
_<proto>)- 仅支持传输层协议:
_tcp(可靠连接)或_udp(无连接)。 - 示例:
_sip._tcp.example.com.→ TCP 端口的 SIP 服务_sip._udp.example.com.→ UDP 端口的 SIP 服务 [citation:1][citation:3]。
- 仅支持传输层协议:
-
域名主体(
<domain>)- 完全限定域名(FQDN):必须包含根域结尾点(如
example.com.),避免解析歧义。 - 层级关系:域名可包含子域(如
_service._tcp.subdomain.example.com.)[citation:2][citation:4]。
- 完全限定域名(FQDN):必须包含根域结尾点(如
💻 实际应用场景
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 记录,格式为:
_<port-name>._<proto>.<svc>.<namespace>.svc.cluster.local.
- 示例:服务
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 域名格式核心要素
| 组件 | 格式要求 | 示例 | 作用 |
|---|---|---|---|
| 服务名称 | _<service> |
_sip、_ldap |
标识服务类型 |
| 协议类型 | _<proto> |
_tcp、_udp |
指定传输协议 |
| 域名主体 | <domain>.(FQDN) |
example.com. |
服务所属域名 |
| 完整格式 | _<service>._<proto>.<domain>. |
_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 中用于定位特定服务的资源记录类型,其标准格式为 _<Service>._<Proto>.<Domain>。以下是支持的 _Service(服务类型) 和 _Proto(协议类型) 的详细分类及常见示例:
🔧 一、_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 记录自动生成格式为
_<port-name>._<proto>.<svc>.<namespace>.svc.cluster.local.,例如_https._tcp.my-svc.default.svc.cluster.local.[citation:1]。- Active Directory:分组记录如
_MSDCS(域控制器)、_SITES(站点特定服务)[citation:4]。
⚠️ 三、配置注意事项
- 域名格式要求:
- 必须为 完全限定域名(FQDN),以点结尾(如
example.com.)[citation:1][citation:4]。 - 服务名和协议名均需包含前缀下划线(如
_http._tcp)。
- 必须为 完全限定域名(FQDN),以点结尾(如
- 记录值依赖:
Target字段的主机名(如sipserver.example.com.)必须存在 A/AAAA 记录,不可指向 CNAME[citation:4][citation:5]。
- 权重与优先级:
- 优先级(Priority):数值越小越优先(
0-65535)。 - 权重(Weight):同优先级时按权重分配流量(
0-65535)[citation:1][citation:3]。
- 优先级(Priority):数值越小越优先(
💎 四、总结
_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]。

浙公网安备 33010602011771号