XML in Network Configuration: NETCONF and YANG
This post introduces XML's role in modern network configuration through NETCONF and YANG. It explains how NETCONF uses XML as its encoding format for structured device communication, and how YANG data models define the schema that XML payloads must conform to. Practical examples of NETCONF RPC mess
NETCONF is the protocol that carries configuration to and from network devices; it encodes its messages in XML and most commonly runs over SSH, on TCP port 830 by default. YANG is the modelling language used to define what that configuration and state data may contain. Together they let automation tools send structured, validated changes instead of scraping CLI text.
If you have spent any time exploring modern network automation, you have probably come across the terms NETCONF and YANG. These two technologies work hand in hand to give network engineers a structured, programmable way to configure and manage network devices. NETCONF carries its data in a familiar format: XML. This post introduces each concept from the ground up, so no prior knowledge of network automation is assumed.
What is XML?
XML (Extensible Markup Language) is a text-based format for representing structured data using nested tags. Each piece of data is wrapped in an opening and closing tag, and tags can be nested inside one another to express hierarchy. For example:
<device>
<hostname>router-1</hostname>
<ip-address>192.168.1.1</ip-address>
</device>This tells you clearly that a device has a hostname of router-1 and an ip-address of 192.168.1.1. The structure is explicit and machine-readable, which makes XML well suited for automation tasks where programs need to reliably read and write configuration data.
Why XML for Network Configuration?
Traditional network management relied on SNMP for monitoring and CLI for configuration. Both have significant limitations when it comes to automation: CLI output is unstructured text that is painful to parse reliably, and SNMP was never designed with configuration in mind. XML solves this by providing a structured, hierarchical data format that both humans and machines can read and validate consistently.
When a router sends configuration data wrapped in XML, your automation script does not have to guess where one value ends and another begins. The tags define the structure, making parsing predictable and reliable.
What is NETCONF?
NETCONF (Network Configuration Protocol) is a network management protocol defined in RFC 6241. It runs over SSH (port 830) and uses XML to encode both its messages and the configuration data being transferred. Think of NETCONF as the protocol layer: it defines what operations you can perform and how requests and responses are structured, while SSH is the transport that carries them.
NETCONF defines a set of operations that map to common management tasks:
- get-config: retrieve the current configuration from a device
- edit-config: modify the configuration on a device
- copy-config: copy an entire configuration from one datastore to another
- delete-config: delete a configuration datastore
- lock/unlock: prevent other sessions from modifying configuration simultaneously
- commit: apply candidate configuration to the running state
A basic NETCONF get-config request looks like this:
<rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<get-config>
<source>
<running/>
</source>
</get-config>
</rpc>Notice the XML structure. The <rpc> element wraps the operation, and child elements define exactly what you want. The device responds with XML containing the requested configuration data.
What is YANG?
YANG (Yet Another Next Generation) is a data modeling language defined in RFC 7950. If NETCONF is the protocol, YANG is the blueprint that defines what data can be sent and in what structure. YANG models describe the valid configuration and state data for a device, including data types, constraints, and relationships between elements.
A simple YANG module might look like this:
module example-interface {
namespace "http://example.com/interface";
prefix "iface";
container interfaces {
list interface {
key "name";
leaf name {
type string;
}
leaf enabled {
type boolean;
default true;
}
leaf ip-address {
type string;
}
}
}
}This YANG model defines that an interfaces container holds a list of interface entries, each with a name, an enabled flag, and an ip-address. When a NETCONF message carries interface configuration, the XML structure must match what this YANG model defines.
How They Work Together
The relationship is straightforward:
- YANG defines the structure and rules for the data (the schema).
- NETCONF transports that data to and from the device using XML encoding.
- Your automation tool (Python with
ncclient, Ansible, NSO) constructs XML payloads that conform to the device's YANG models and sends them via NETCONF.
Cisco IOS-XE, IOS-XR, and NX-OS all support NETCONF and publish their YANG models publicly on GitHub at github.com/YangModels/yang. This means you can inspect exactly what data a device accepts before writing a single line of automation code.
A Quick Practical Note
To experiment with NETCONF on a Cisco IOS XE device, you first need to enable it:
Router(config)# netconf-yangThen you can connect from a Linux machine using the ncclient Python library to send XML-encoded NETCONF operations programmatically. This is where learning XML structure pays off directly: every configuration you push to a device via NETCONF is XML that you construct or validate against a YANG model.
NETCONF, YANG and XML: common questions
What is the difference between NETCONF and YANG?
NETCONF (RFC 6241) is the protocol that transports the data and defines operations such as get-config and edit-config. YANG (RFC 7950) is the language used to write data models: modules that define the structure and constraints the data must follow.
Which port does NETCONF use?
When NETCONF runs over SSH, which is the usual transport, it uses TCP port 830 by default.
Why use XML instead of CLI output for automation?
CLI output is unstructured text that scripts have to parse by guesswork. XML tags define exactly where each value starts and ends, so reading and writing configuration is predictable.
What are the main NETCONF operations?
get (configuration plus operational state), get-config (configuration only), edit-config, copy-config, delete-config, lock and unlock, and commit, which applies the candidate configuration on devices that support a candidate datastore.
How do I enable NETCONF on an IOS XE device?
In global configuration mode, run netconf-yang. You can then connect from a script, for example with the Python ncclient library.
What's Next
Now that you understand how XML powers NETCONF and YANG, the logical next step is learning how to work with XML programmatically. In the next post, we will look at parsing and building XML in Python using the xml.etree.ElementTree library, which will give you the hands-on skills to build real NETCONF automation workflows.
Further Reading
- RFC 6241: NETCONF Protocol
- RFC 7950: YANG Data Modeling Language
- YangModels on GitHub
- ncclient Documentation