Network management: SNMP, NETCONF, and YANG
Once a network has more than a handful of devices, typing commands into each one stops working. Network management is the set of tools and protocols for monitoring, configuring, and controlling devices from one place, with the same result every time.
The management framework
Section titled “The management framework”Every management system has the same five parts, whatever protocol it uses.
| Part | What it is | Example |
|---|---|---|
| Managing server | Software that collects data, analyzes it, and sends commands | Monitoring platform, automation controller |
| Managed device | Equipment with something to manage | Router, switch, firewall, server, UPS, temperature sensor |
| Agent | A process on the device that answers the server and acts on its behalf | snmpd, a NETCONF server |
| Data | State the device keeps (see below) | Interface settings, OSPF neighbors, error counters |
| Management protocol | The messages between server and agent | SNMP, NETCONF, gNMI |
The data on a device falls into three groups:
| Kind | Meaning | Example |
|---|---|---|
| Configuration | Set by an administrator | IP address on an interface, configured speed |
| Operational | Learned while running | OSPF neighbor list, ARP table |
| Statistics | Counters and readings | Dropped packets, fan speed |
The protocol does not manage anything by itself. It carries the requests, replies, and alerts. Agents can also push notifications when something unusual happens, so the server does not have to poll for everything.
Three ways to work
Section titled “Three ways to work”| Method | Strength | Weakness |
|---|---|---|
| CLI over SSH | Everything the device can do, and it is what operators know | Syntax differs between vendors. Free-form text is error-prone and hard to automate safely |
| SNMP | Universal support for monitoring | Weak for configuration. Old versions have poor security |
| NETCONF and YANG | Structured, validated configuration with transactions | Needs device support and a modeling effort |
Modern practice is to treat device configuration as data, keep it in version control, and push it with automation. See Infrastructure as code for the broader approach.
SNMP (Simple Network Management Protocol) reads and sets values on devices. Almost every network device speaks it, which is why monitoring systems still depend on it.
How it works
Section titled “How it works”- A manager sends a request to an agent to read (
Get) or change (Set) a value. - The agent can also send an unsolicited trap when something happens, such as a link going down or a failed login.
- Messages travel over UDP. Requests go to port 161 and traps to port 162. UDP is unreliable, so the manager must handle timeouts and retries itself.
| PDU | Direction | Purpose |
|---|---|---|
GetRequest | Manager to agent | Read one or more values |
GetNextRequest | Manager to agent | Read the next value in order, which is how a manager walks a table |
GetBulkRequest | Manager to agent | Read a large block, such as a whole table, in one exchange |
SetRequest | Manager to agent | Change a value |
Response | Agent to manager | Return values or confirm a change |
Trap | Agent to manager | Report an event |
InformRequest | Manager to manager, or agent to manager with acknowledgment | Send data and get a confirmation |
MIBs and OIDs
Section titled “MIBs and OIDs”The data an agent exposes is defined by a Management Information Base (MIB). A MIB is a tree of objects. Each object has a numeric object identifier (OID) and a name, and is written in a language called SMI that fixes its type and access (read-only or read-write). Hundreds of standard MIB modules exist, for IP, TCP, UDP, interfaces, and more. Vendors add private ones.
ipSystemStatsInDelivers OBJECT-TYPE SYNTAX Counter32 MAX-ACCESS read-only STATUS current DESCRIPTION "Datagrams delivered to IP user-protocols, including ICMP."Some OIDs worth knowing:
| OID | Name | Meaning |
|---|---|---|
1.3.6.1.2.1.1.3.0 | sysUpTime.0 | Time since the agent restarted |
1.3.6.1.2.1.2.2.1.10 | ifInOctets | Bytes received, 32-bit counter |
1.3.6.1.2.1.31.1.1.1.6 | ifHCInOctets | Bytes received, 64-bit counter |
Security and versions
Section titled “Security and versions”SNMPv1 and v2c authenticate with a community string, which is a shared password sent in plain text. Operators have therefore used them read-only. SNMPv3 adds proper authentication, encryption, and replay protection, and is the only version suitable for changing configuration or crossing untrusted networks.
- Use v3 with authentication and encryption (
authPriv). - Restrict the agent to the monitoring server’s address with an ACL.
- Never leave the default community strings (
public,private). - Keep credentials in
~/.snmp/snmp.conf, not on the command line, wherepsshows them.
# Read one value (v2c, for a lab device only)snmpget -v2c -c public 192.0.2.10 sysUpTime.0
# SNMPv3 with authentication and encryption: walk the interface namessnmpwalk -v3 -l authPriv -u monitor -a SHA -x AES 192.0.2.10 ifDescr
# Receive traps on this hostsudo snmptrapd -f -Lo| Symptom | Likely cause | Fix |
|---|---|---|
Timeout: No Response | UDP 161 blocked, ACL excludes the manager, or wrong community or v3 user | Test reachability, then compare credentials and the agent’s allowed sources |
No Such Object available | The device does not implement that OID, or the MIB is not loaded | Walk the parent OID, or load the MIB file |
| Traffic graphs with negative or huge spikes | 32-bit counter wrapped | Use the 64-bit counters |
| Traps never arrive | No trap destination on the device, UDP 162 filtered, or snmptrapd rejects the user | Configure the destination and allow the port |
NETCONF and YANG
Section titled “NETCONF and YANG”SNMP monitors well and configures poorly. Operators asked for something that handles whole configurations, validates them, and rolls back on failure. NETCONF and YANG were built for that.
NETCONF
Section titled “NETCONF”NETCONF is a protocol for reading and changing device configuration and state. It uses remote procedure calls with XML messages, over a secure session. SSH on port 830 is the usual transport, and TLS is also defined. The management server is the client and the device is the server.
A session runs like this:
- The client connects and both sides exchange
<hello>messages that list their capabilities. - The client sends
<rpc>requests and the device answers with<rpc-reply>. - If subscribed, the device sends
<notification>messages for events. - The client ends the session with
<close-session>.
| Operation | Purpose |
|---|---|
<get-config> | Read part or all of a configuration datastore |
<get> | Read configuration plus live operational data |
<edit-config> | Change the configuration. Returns <ok> or an <rpc-error> |
<lock> and <unlock> | Take the datastore exclusively, so a CLI user or script cannot change it midway |
<commit> and <discard-changes> | Apply or abandon staged changes (with the candidate datastore) |
<create-subscription> | Stream notifications to the client |
A device can hold several datastores: the running configuration in use, an optional candidate where changes are staged and checked, and a startup copy for boot. The usual safe flow is to lock, edit the candidate, validate, commit, and unlock. If the edit is bad, the change is discarded and the running configuration stays as it was.
Atomic change within one device comes from this model. Changes spanning several devices need an orchestrator on top that commits to each and rolls all of them back if one fails.
# pip install ncclientimport osfrom ncclient import manager
with manager.connect( host="192.0.2.1", port=830, username="netops", password=os.environ["NETCONF_PASSWORD"], hostkey_verify=True,) as m: print(m.get_config(source="running").data_xml)YANG is the language that describes the data NETCONF carries. A YANG module defines the structure, data types, and rules of the configuration and the notifications a device can send. It does the same job SMI does for SNMP, with validation built in.
leaf mtu { type uint16 { range "68..9216"; } description "Maximum transmission unit of the interface.";}With that definition, a value of 50 is rejected before it ever reaches the device. YANG 1.1 is RFC 7950, which replaced the first version, RFC 6020. Standard and vendor modules exist for interfaces, routing, and more. RESTCONF (RFC 8040) exposes the same YANG-modeled data over HTTP, for tools that prefer REST.
Streaming telemetry
Section titled “Streaming telemetry”Polling every minute misses short events and loads the device with requests. Streaming telemetry reverses it: the device pushes selected data at a set interval or on change. gNMI is a common protocol for this. It uses gRPC and a compact binary encoding, and a client subscribes to YANG paths. Telemetry feeds time-series databases and dashboards at much finer resolution than SNMP polling.
SNMP compared with NETCONF and YANG
Section titled “SNMP compared with NETCONF and YANG”| SNMP and MIB | NETCONF and YANG | |
|---|---|---|
| Best at | Device monitoring and metrics | Configuration management and automation |
| Data model | SMI | YANG |
| Transport | UDP, 161 and 162 | SSH (830) or TLS, XML RPC |
| Config safety | Plain Set, rarely used | Locks, candidate datastore, validation, rollback |
| Typical tool | Net-SNMP, snmp_exporter, Zabbix, LibreNMS | ncclient, Ansible network modules, vendor controllers |
Most networks run both: SNMP or telemetry for what is happening, and NETCONF or another API for changing it. Lock down all management protocols to a dedicated management network. See Network hardening.