Managing a few routers through the CLI works, but configuring 200 devices manually does not scale.

Figure 1 – Configuring 200 devices manually does not scale
CLI Text vs. Structured XML
Every CLI command returns unstructured text formatted for human eyes.
Extracting an IP address from show ip interface brief requires fragile text parsing that breaks whenever an IOS update shifts spacing or adds a column.
Figure 2 – CLI vs NETCONF
On the left, the CLI outputs raw text that your script must split line by line.
On the right, NETCONF returns structured XML mapped directly to a YANG data model.Answer the question below
What format does NETCONF use to return data to your scripts?
NETCONF Architecture
NETCONF (Network Configuration Protocol, RFC 6241) was built specifically for programmatic configuration management:
Data models use YANG to define the structure of device settings.
Encoding uses XML so scripts can read and write values without text parsing.
Transport uses SSH to provide an encrypted, authenticated channel.
Before NETCONF
Before NETCONF, SNMP was the main protocol for network management, but it was designed for monitoring rather than pushing configuration changes.
Approach
Designed for
Data format
Configuration support
CLI
Human operators
Unstructured text
Full, but manual
SNMP
Monitoring and polling
MIB/OID (structured but rigid)
Limited and complex
NETCONF
Programmatic management
XML (structured, flexible)
Full read and write
Table 1 – CLI vs SNMP vs NETCONF
Answer the question below
What data modeling language does NETCONF rely on to define the structure of configuration data?
NETCONF operates across four layers, from network transport at the bottom to data models at the top.
The Four Layers

Figure 3 – The four NETCONF layers
Transport carries the connection, typically over SSH on TCP port 830 instead of standard port 22.
Messages wrap every exchange inside an
<rpc>request and an<rpc-reply>response.Operations define the actions you perform on the device, such as get, edit, lock, and commit.
Content consists of the YANG models that describe your device configuration and operational state.
Session Establishment
When your script connects to a router, both sides exchange a hello message to negotiate capabilities and list supported YANG models.

Figure 4 – Capabilities exchange
Here is a simplified example of what the router sends back:
<?xml version="1.0" encoding="UTF-8"?> <hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <capabilities> <capability>urn:ietf:params:netconf:base:1.1</capability> <capability>urn:ietf:params:netconf:capability:candidate:1.0</capability> <capability>http://cisco.com/ns/yang/Cisco-IOS-XE-native</capability> </capabilities> <session-id>42</session-id> </hello>The capabilities block lists every YANG model and feature the router supports; if a model is absent, you cannot use it.
The session-id is a unique number assigned by the device to track your active session.Answer the question below
What type of message do both the client and device send at the beginning of a NETCONF session?
RPC Request and Reply
After the hello exchange, your script sends an rpc message containing an operation and an optional filter, and the device replies with an rpc-reply.

Figure 5 – RPC request with a subtree filter
The reply returns either the requested XML data or a status indicator confirming success or failure.

Figure 6 – RPC reply with structured XML data
Every request receives one structured reply, leaving no partial output to parse.
Answer the question below
What is the default TCP port used by NETCONF?
Datastores and Operations
NETCONF organizes device configurations into up to three datastores:

Figure 7 – NETCONF datastores
The candidate datastore lets you stage multiple changes, validate them, and apply everything at once.
If an error occurs, you discard the candidate and the running configuration remains untouched.Operation
Purpose
<get>Retrieve running config and operational state
<get-config>Retrieve config data only from a specific datastore
<edit-config>Modify a datastore (merge, replace, delete, or create)
<copy-config>Copy a datastore to another (such as running to startup)
<lock> / <unlock>Lock a datastore to prevent concurrent modifications
<commit>Apply the candidate config to the running datastore
<discard-changes>Revert the candidate to match the running config
Table 2 – NETCONF operations
When using the candidate datastore, scripts follow a lock-edit-commit-unlock workflow to make safe, atomic changes.
Inside edit-config, you specify how the router applies your XML payload:
merge (default) combines your new data with the existing configuration.
replace overwrites the existing configuration at that level with your new data.
delete removes the specified configuration element.
create adds the element only if it does not already exist.
On Cisco IOS-XE, you can also target the running datastore directly with edit-config to apply changes immediately without a commit, which is the approach used in the lab below.
Answer the question below
Which NETCONF operation applies the candidate configuration to the running datastore?
In this lab, you configure SSH prerequisites, enable NETCONF on R1, and run Python scripts with ncclient to read and modify the configuration.

Figure 8 – Lab topology
R1 (192.168.1.1) is a Cisco IOS-XE router.
Workstation (192.168.1.10) runs Python with the ncclient library installed and connects to R1 on TCP port 830.
SSH Prerequisites
NETCONF runs over SSH, so R1 needs SSHv2 enabled along with a privilege 15 local user account.
Set a hostname and domain name first, as both are required to generate the RSA key pair:Router> enable Router# conf t Enter configuration commands, one per line. End with CNTL/Z. Router(config)# hostname R1 R1(config)# ip domain-name lab.localGenerate a 2048-bit RSA key pair and create a privilege 15 admin account:
R1(config)# crypto key generate rsa modulus 2048 The name for the keys will be: R1.lab.local % The key modulus size is 2048 bits % Generating 2048 bit RSA keys, keys will be non-exportable... [OK] (elapsed time was 1 seconds) R1(config)# username admin privilege 15 secret cisco123NETCONF requires privilege level 15 because it grants full read and write access to the router configuration.
Enable SSHv2, restrict VTY lines to SSH with local authentication, and exit configuration mode:R1(config)# ip ssh version 2 R1(config)# line vty 0 4 R1(config-line)# transport input ssh R1(config-line)# login local R1(config-line)# endVerify that SSHv2 is active:
R1# show ip ssh SSH Enabled - version 2.0 // Omitted for brevityEnabling NETCONF on IOS-XE
Enable the NETCONF agent in global configuration mode:
R1# conf t Enter configuration commands, one per line. End with CNTL/Z. R1(config)# netconf-yang R1(config)# endnetconf-yang activates the NETCONF subsystem and opens TCP port 830.
Verifying the Agent
Check active NETCONF sessions to confirm the agent is listening:
R1# show netconf-yang sessions There are no active sessionsConfirm that netconf-yang appears in the running configuration:
R1# show run | include netconf netconf-yangVerify that the background YANG management processes are running:
R1# show platform software yang-management process confd : Running nesd : Running syncfd : Running ncsshd : Running dmiauthd : Running nginx : Running ndbmand : Running pubd : Runningncsshd handles NETCONF over SSH; once it shows Running, R1 is ready for connections.
Answer the question below
Which process listed in the yang-management output is responsible for NETCONF over SSH?
Reading Configuration with Python
Run this script on your workstation to retrieve the full running configuration using ncclient:
from ncclient import manager with manager.connect( host="192.168.1.1", port=830, username="admin", password="cisco123", hostkey_verify=False ) as m: config = m.get_config(source="running") print(config)manager.connect() opens an SSH session to R1 on port 830 and completes the hello exchange.
hostkey_verify=False skips SSH host key checks in the lab (verify host keys in production).
m.get_config(source="running") sends a get-config RPC and prints the full running configuration in XML.
To retrieve only interface settings instead of the entire configuration, pass a subtree filter to get_config():
from ncclient import manager filter_xml = """ <filter> <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native"> <interface/> </native> </filter> """ with manager.connect( host="192.168.1.1", port=830, username="admin", password="cisco123", hostkey_verify=False ) as m: config = m.get_config(source="running", filter=filter_xml) print(config)As shown in Figure 5, the filter element restricts the RPC reply to the interface container inside the native YANG model.
Answer the question below
What XML element is used to request only a specific part of the configuration in a get-config operation?
Pushing Configuration with Python
To modify the configuration, send an XML payload with edit_config() targeting the running datastore:
from ncclient import manager config_xml = """ <config> <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native"> <interface> <GigabitEthernet> <name>1</name> <description>Configured via NETCONF</description> </GigabitEthernet> </interface> </native> </config> """ with manager.connect( host="192.168.1.1", port=830, username="admin", password="cisco123", hostkey_verify=False ) as m: response = m.edit_config(target="running", config=config_xml) print(response)When the router applies the change, it returns an rpc-reply containing
<ok/>.
Figure 9 – Python script connecting to R1 via NETCONF
Verify on R1 that the description was applied:
R1# show run interface GigabitEthernet1 Building configuration... Current configuration : 98 bytes ! interface GigabitEthernet1 description Configured via NETCONF ip address 192.168.1.1 255.255.255.0 endWhen the Python with block exits, ncclient closes the NETCONF session automatically.
Confirm on R1 that the session count is back to zero:R1# show netconf-yang sessions Number of sessions : 0Your script connected over port 830, applied the change, and closed the session cleanly.
In the next lesson, you will perform the same tasks over HTTPS using RESTCONF.Answer the question below
What IOS-XE command enables the NETCONF agent on your router?
Answer the question below
A script sends lock, edit-config, commit, unlock: how many replies contain <ok/>?