Skip to content
Documentation Background

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.


Every management system has the same five parts, whatever protocol it uses.

PartWhat it isExample
Managing serverSoftware that collects data, analyzes it, and sends commandsMonitoring platform, automation controller
Managed deviceEquipment with something to manageRouter, switch, firewall, server, UPS, temperature sensor
AgentA process on the device that answers the server and acts on its behalfsnmpd, a NETCONF server
DataState the device keeps (see below)Interface settings, OSPF neighbors, error counters
Management protocolThe messages between server and agentSNMP, NETCONF, gNMI

The data on a device falls into three groups:

KindMeaningExample
ConfigurationSet by an administratorIP address on an interface, configured speed
OperationalLearned while runningOSPF neighbor list, ARP table
StatisticsCounters and readingsDropped 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.

MethodStrengthWeakness
CLI over SSHEverything the device can do, and it is what operators knowSyntax differs between vendors. Free-form text is error-prone and hard to automate safely
SNMPUniversal support for monitoringWeak for configuration. Old versions have poor security
NETCONF and YANGStructured, validated configuration with transactionsNeeds 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.

  • 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.
PDUDirectionPurpose
GetRequestManager to agentRead one or more values
GetNextRequestManager to agentRead the next value in order, which is how a manager walks a table
GetBulkRequestManager to agentRead a large block, such as a whole table, in one exchange
SetRequestManager to agentChange a value
ResponseAgent to managerReturn values or confirm a change
TrapAgent to managerReport an event
InformRequestManager to manager, or agent to manager with acknowledgmentSend data and get a confirmation

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:

OIDNameMeaning
1.3.6.1.2.1.1.3.0sysUpTime.0Time since the agent restarted
1.3.6.1.2.1.2.2.1.10ifInOctetsBytes received, 32-bit counter
1.3.6.1.2.1.31.1.1.1.6ifHCInOctetsBytes received, 64-bit counter

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, where ps shows them.
Terminal window
# 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 names
snmpwalk -v3 -l authPriv -u monitor -a SHA -x AES 192.0.2.10 ifDescr
# Receive traps on this host
sudo snmptrapd -f -Lo
SymptomLikely causeFix
Timeout: No ResponseUDP 161 blocked, ACL excludes the manager, or wrong community or v3 userTest reachability, then compare credentials and the agent’s allowed sources
No Such Object availableThe device does not implement that OID, or the MIB is not loadedWalk the parent OID, or load the MIB file
Traffic graphs with negative or huge spikes32-bit counter wrappedUse the 64-bit counters
Traps never arriveNo trap destination on the device, UDP 162 filtered, or snmptrapd rejects the userConfigure the destination and allow the port

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 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:

  1. The client connects and both sides exchange <hello> messages that list their capabilities.
  2. The client sends <rpc> requests and the device answers with <rpc-reply>.
  3. If subscribed, the device sends <notification> messages for events.
  4. The client ends the session with <close-session>.
OperationPurpose
<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 ncclient
import os
from 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.


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 and MIBNETCONF and YANG
Best atDevice monitoring and metricsConfiguration management and automation
Data modelSMIYANG
TransportUDP, 161 and 162SSH (830) or TLS, XML RPC
Config safetyPlain Set, rarely usedLocks, candidate datastore, validation, rollback
Typical toolNet-SNMP, snmp_exporter, Zabbix, LibreNMSncclient, 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.