# NETCONF

NETCONF（网络配置协议）是 IETF 制定的一种协议，用于安装、操作和删除网络设备的配置，配置数据和协议消息均采用 XML 编码，协议操作以远程过程调用（RPC）的方式实现。<sup>[1](https://www.rfc-editor.org/info/rfc6241/)</sup> 当前版本由 RFC 6241（2011 年 6 月）定义，该文档废止了 2006 年 12 月的原始版本 RFC 4741。<sup>[1](https://www.rfc-editor.org/info/rfc6241/)</sup><sup> • </sup><sup>[2](https://www.rfc-editor.org/info/rfc4741/)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义文档 | RFC 6241《网络配置协议》，2011 年 6 月；废止 RFC 4741（2006 年 12 月）<sup>[1](https://www.rfc-editor.org/info/rfc6241/)</sup> |
| 编码 | 所有消息必须是 UTF-8 编码的良构 XML；基础命名空间为 `urn:ietf:params:xml:ns:netconf:base:1.0`<sup>[1](https://www.rfc-editor.org/info/rfc6241/)</sup> |
| 协议分层 | 安全传输层、消息层、操作层和内容层；内容层不在 RFC 6241 的范围内<sup>[1](https://www.rfc-editor.org/info/rfc6241/)</sup> |
| 强制传输 | 每个实现都必须支持 RFC 6242 定义的 SSH 传输映射<sup>[1](https://www.rfc-editor.org/info/rfc6241/)</sup> |
| 数据存储 | NMDA（RFC 8342，2018 年 3 月）定义了 <candidate>、<running>、<intended>、<startup> 以及只读的 <operational> 数据存储<sup>[3](https://www.rfc-editor.org/info/rfc8342/)</sup> |
| NMDA 扩展 | RFC 8526（2019 年 3 月）增加了 <get-data> 和 <edit-data>，并对 <lock>、<unlock> 和 <validate> 进行了增强<sup>[4](https://datatracker.ietf.org/doc/rfc8526/)</sup> |
| HTTP 姊妹协议 | RESTCONF（RFC 8040，2017 年 1 月）通过 HTTP 暴露相同的 YANG 建模数据存储概念，支持 XML 或 JSON 编码<sup>[5](https://www.rfc-editor.org/info/rfc8040/)</sup> |

## 协议架构

RFC 6241 将 NETCONF 组织为四层。安全传输层提供客户端与服务器之间的通信路径；NETCONF 可以运行在任何满足一组基本要求的传输协议之上。消息层提供与传输无关的成帧机制，用于对 RPC 和通知进行编码。操作层定义了以 RPC 方法形式调用、参数采用 XML 编码的基础协议操作。内容层即数据模型本身，被有意排除在基础协议范围之外，由独立的标准化工作处理，主要是 YANG 数据建模语言。<sup>[1](https://www.rfc-editor.org/info/rfc6241/)</sup>

该协议独立于会话层和传输，因此可以为多种传输协议定义映射。SSH 是唯一强制要求的传输方式：NETCONF 实现必须支持 RFC 6242 定义的 SSH 映射，该映射将 NETCONF 作为 SSH 子系统运行，在 SSH 传输协议之上使用 SSH 连接协议。<sup>[1](https://www.rfc-editor.org/info/rfc6241/)</sup><sup> • </sup><sup>[6](https://www.rfc-editor.org/rfc/rfc6242.html)</sup>

## SSH 上的传输与成帧

RFC 6242 定义了如何在 SSH 会话内分隔 NETCONF 消息。2006 年的原始映射（RFC 4742）使用字符序列 `]]>]]>` 分隔消息，假设该序列不会出现在良构 XML 中。这个假设是错误的：该序列可以合法地出现在 XML 属性、注释和处理指令中。因此 RFC 6242 引入了分块成帧机制，每条消息被拆分为若干块，每块前加长度前缀，以标记终止；当双方在最初的 <hello> 交换中都声明 `:base:1.1` 能力时，整个会话均使用该机制。否则会话回退到旧的消息结束符成帧方式，但 <hello> 消息之后仍跟 `]]>]]>`。<sup>[6](https://www.rfc-editor.org/rfc/rfc6242.html)</sup>

## 操作与数据存储

NETCONF 客户端通过对命名数据存储执行 RPC 操作来编辑配置。支持 `:candidate` 能力的设备维护一个候选配置，客户端编辑该配置后，通过 <commit> 操作将其安装到运行配置上。<sup>[2](https://www.rfc-editor.org/info/rfc4741/)</sup><sup> • </sup><sup>[7](https://www.juniper.net/documentation/us/en/software/junos/netconf/topics/task/netconf-configuration-committing.html)</sup> 通过 <confirmed> 参数请求的确认提交会使变更暂时生效：如果客户端未在指定时间内确认，设备将自动回滚到先前提交的配置。这对于验证变更是否有效且不会导致操作员无法进行管理访问非常有用。<sup>[8](https://www.juniper.net/documentation/us/en/software/junos/netconf/topics/task/netconf-configuration-committing-with-confirmation.html)</sup>

原始 NETCONF 模型要求将配置和运行状态分开建模，这导致 YANG 模式中出现重复。网络管理数据存储架构（NMDA，RFC 8342，2018 年 3 月）对此进行了重构：它定义了常规配置数据存储（<running>、<candidate>、<startup>、<intended>）、动态配置数据存储，以及一个只读的 <operational> 数据存储，其中包含系统状态和所有实际使用的配置，包括已应用的、学习到的和系统提供的值。从 <operational> 检索时，无论 YANG 默认值如何，都返回实际使用的值。<sup>[3](https://www.rfc-editor.org/info/rfc8342/)</sup> RFC 8526（2019 年 3 月）扩展了 NETCONF 以访问这些数据存储，增加了 <get-data> 和 <edit-data> 操作，并增强了 <lock>、<unlock> 和 <validate>，同时要求 NMDA 服务器支持 YANG 库，以便客户端发现存在哪些数据存储。<sup>[4](https://datatracker.ietf.org/doc/rfc8526/)</sup>

## 与 YANG 和 RESTCONF 的关系

NETCONF 承载的数据结构由 YANG 数据模型描述；NETCONF 的数据存储概念正是将 YANG 模型绑定到管理协议的纽带。<sup>[3](https://www.rfc-editor.org/info/rfc8342/)</sup> RESTCONF 在 RFC 8040（2017 年 1 月）中标准化，它将 HTTP 方法应用于 NETCONF 中定义的相同数据存储概念，使用 YANG 版本 1 或 1.1 数据。它将数据编码为 `application/yang-data+xml` 或 `application/yang-data+json`，因此知道服务器 YANG 模块的客户端可以推导出所有资源 URL 和请求结构，无需服务器提供超媒体链接。<sup>[5](https://www.rfc-editor.org/info/rfc8040/)</sup> 一份 IEEE 标准演示这样总结实际选择：在 NETCONF 和 RESTCONF 之间选择很大程度上是偏好问题，NETCONF 历史更长、支持更好，而 RESTCONF 适合习惯于 REST 和 JSON 的程序员。<sup>[9](https://standards.ieee.org/wp-content/uploads/import/documents/other/eipatd-presentations/2021/d2-08.pdf)</sup> 两种协议在行业规范中同时出现；例如，ETSI 的 NFV 多站点连接工作将 NETCONF（XML 编码）和 RESTCONF（XML 或 JSON）列为 IETF 接口协议格式，并以 YANG 作为数据模型语言。<sup>[10](https://www.etsi.org/deliver/etsi_gr/NFV-SOL/001_099/017/03.03.01_60/gr_NFV-SOL017v030301p.pdf)</sup>

## 部署与生态系统

NETCONF 和 YANG 支撑着当代 IETF 网络管理框架，多厂商互操作性测试已经验证了来自思科、诺基亚和华为的控制器通过 NETCONF 向其他厂商的路由器推送 YANG 建模配置，包括 L3VPN、EVPN 和基于分段路由的 MPLS 的服务创建。<sup>[11](https://eantc.de/wp-content/uploads/2022/12/EANTC-NETCONFYANG-SDN-Mgmt-Interop-Test-2020-WhitePaper.pdf)</sup> 开源实现包括 netopeer（一个 NETCONF 服务器）和 ncclient（一个 Python 客户端），两者都支持在强制 SSH 传输上运行 NETCONF v1.1。<sup>[12](https://arxiv.org/abs/2112.14612)</sup> [自动化](https://www.edgepedia.org/zh/automation)工具也构建在该协议之上；例如，Ansible 的 netconf_config 模块以候选或运行数据存储为目标，其选项可能要求 `:candidate` 和 `:confirmed-commit` 能力。<sup>[13](https://docs.ansible.com/projects/ansible/latest/collections/ansible/netcommon/netconf_config_module.html)</sup>

IETF NETCONF 工作组继续扩展该协议，目前有关于 YANG 通知自适应订阅、分布式通知订阅、NETCONF 客户端和服务器 YANG 数据模型以及事务 ID 机制的活跃草案。<sup>[14](https://datatracker.ietf.org/wg/netconf/documents/)</sup>

## References

1. [RFC 6241: Network Configuration Protocol (NETCONF), RFC Editor](https://www.rfc-editor.org/info/rfc6241/)
2. [RFC 4741: NETCONF Configuration Protocol, RFC Editor](https://www.rfc-editor.org/info/rfc4741/)
3. [RFC 8342: Network Management Datastore Architecture (NMDA), RFC Editor](https://www.rfc-editor.org/info/rfc8342/)
4. [RFC 8526: NETCONF Extensions to Support the Network Management Datastore Architecture, IETF Datatracker](https://datatracker.ietf.org/doc/rfc8526/)
5. [RFC 8040: RESTCONF Protocol, RFC Editor](https://www.rfc-editor.org/info/rfc8040/)
6. [RFC 6242: Using the NETCONF Protocol over Secure Shell (SSH), RFC Editor](https://www.rfc-editor.org/rfc/rfc6242.html)
7. [Commit the Candidate Configuration Using NETCONF, Junos OS documentation](https://www.juniper.net/documentation/us/en/software/junos/netconf/topics/task/netconf-configuration-committing.html)
8. [Commit the Candidate Configuration Only After Confirmation Using NETCONF, Junos OS documentation](https://www.juniper.net/documentation/us/en/software/junos/netconf/topics/task/netconf-configuration-committing-with-confirmation.html)
9. [Status Quo of Dynamic Network Management with YANG-Based Configuration Models, IEEE](https://standards.ieee.org/wp-content/uploads/import/documents/other/eipatd-presentations/2021/d2-08.pdf)
10. [ETSI GR NFV-SOL 017 V3.3.1: Protocols and Data Models for Multi-site Connectivity Services](https://www.etsi.org/deliver/etsi_gr/NFV-SOL/001_099/017/03.03.01_60/gr_NFV-SOL017v030301p.pdf)
11. [Multi-Vendor NETCONF/YANG-Based SDN Management Interoperability Test 2020 White Paper, EANTC](https://eantc.de/wp-content/uploads/2022/12/EANTC-NETCONFYANG-SDN-Mgmt-Interop-Test-2020-WhitePaper.pdf)
12. [Managing Home Routers with NETCONF over TLS and NETCONF Call Home, arXiv:2112.14612](https://arxiv.org/abs/2112.14612)
13. [ansible.netcommon.netconf_config module, Ansible documentation](https://docs.ansible.com/projects/ansible/latest/collections/ansible/netcommon/netconf_config_module.html)
14. [Network Configuration (netconf) Working Group documents, IETF Datatracker](https://datatracker.ietf.org/wg/netconf/documents/)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › Networking fundamentals and architecture › Internet protocol suite

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/netconf

English original: https://www.edgepedia.org/netconf
