skip to content

YANG

Modules, containers, lists and typed leaves describe a device's configuration and state, whatever protocol carries them. Automation questions usually land on the model, not the transport.

on this pageshow

explore

questions

page 1 of 2

In a YANG module, what do the namespace and prefix statements each do, and which one identifies the module's data on the wire?

level: juniorimportance: must knowfreq 20%

answer

  1. one is global, one is local
  2. a URI that never changes
  3. importers may pick their own
  4. XML by URI, JSON by module name

basics

~20 s

A YANG namespace is a globally unique URI that qualifies the module's definitions and never changes; the prefix is a short local handle an importer may rename. Encoded data uses the namespace in XML and the module name in JSON, never the prefix.

solid answer

~40 s

Every YANG module header carries exactly one `namespace` and exactly one `prefix` (RFC 7950 §7.1.1). The `namespace` is a URI — `urn:ietf:params:xml:ns:yang:<module-name>` for IETF standard modules, an organization-owned URI otherwise — and the module's elements are qualified by it in the XML encoding, which is why §11 forbids changing it after publication. The `prefix` is only the module's suggested short name: it may qualify local names, and each importer assigns its own prefix inside its `import` statement, reusing the module's one unless two imports clash. Because prefixes are local, no encoding relies on them for identity: XML uses the namespace URI, while the JSON encoding (RFC 7951) and RESTCONF paths (RFC 8040) qualify names with the module name, as in `ietf-interfaces:interfaces`.

code

yang · 20 lines
yang
module example-system {
  yang-version 1.1;
  namespace "urn:example:system";
  prefix sys;

  import ietf-interfaces {
    prefix intf;   // local choice; the module's own prefix is if
  }
  import ietf-yang-types {
    prefix yang;
  }

  organization "Example Org";
  contact "[email protected]";
  description "Documentation example.";

  revision 2026-03-01 {
    description "Initial revision.";
  }
}

go deeper

for a junior

Recall the three identities: module name and namespace are global and permanent, the prefix is a local nickname. Name which one XML uses and which one JSON uses.

for a middle

Explain the import prefix: the importer chooses it, should reuse the module's own, and must rename on a clash. Show that a submodule's data lands in its module's namespace.

for a senior

Show the operational consequence: client code keyed on prefixes breaks when a server or importer picks another prefix, while code keyed on namespace or module name survives every revision.

for a principal

Argue for namespace and naming policy across an estate's private modules: an owned URI scheme, organization-wide module-name prefixes, and why neither may ever be recycled.

## Three names for one module A YANG module (RFC 7950 defines YANG 1.1; RFC 6020 still defines version 1) is identified in three different ways, and interview answers often blur them: | Name | Statement | Scope | May it change after publication? | |---|---|---|---| | **Module name** | `module <name>` | Global — unique within a server and, for published modules, in the IANA "YANG Module Names" registry | No (§11) | | **Namespace** | `namespace "<URI>"` | Global — a URI that must not collide with anyone else's | No (§11) | | **Prefix** | `prefix <identifier>` | Local — inside one module or submodule's text | Yes, if every local use changes with it (§11) | The module substatement table in §7.1.1 makes `yang-version`, `namespace` and `prefix` mandatory, exactly once each. A module with no `yang-version` statement, or with the value `1`, is a YANG version 1 module under RFC 6020; a YANG 1.1 module must say `yang-version 1.1;`. ## The namespace: global and permanent The `namespace` statement binds the module to an XML namespace — a globally unique URI. In the XML encoding that NETCONF carries, the module's elements are qualified by that URI — including nodes it instantiates from an imported grouping, which take the namespace of the module that uses the grouping (§7.1.3). Two consequences follow: - **It has to be unique.** RFC 7950 §5.3 says namespaces for modules published in RFC streams are assigned by IANA, while private modules choose a URI their organization owns so it cannot collide — for example `https://example.com/ns/example-system` or `urn:example:system`. - **It cannot change.** RFC 7950 §11 says the `namespace` statement MUST NOT be changed, since all XML elements are qualified by it. Changing it would make every stored and transmitted instance belong to a different module. RFC 9907, the authoring guidelines, recommends the form `urn:ietf:params:xml:ns:yang:<module-name>` for Standards Track modules, so the URI usually repeats the module name — a convention that helps humans, not a rule the language enforces. ## The prefix: a local alias The `prefix` statement plays two roles (RFC 7950 §7.1.4): 1. **Inside the module itself** it is the module's own short name, which the module may use on its local definitions and which it suggests to importers. 2. **Inside an `import` statement** it is the handle *the importer* chooses for the imported module; references then read `if:ifIndex`, `yang:counter64` and so on. An importer SHOULD reuse the module's own prefix, but if two imported modules declare the same prefix, at least one MUST be imported under a different one. All prefixes used inside one module or submodule, its own included, must be unique there. Because the prefix belongs to the text of one module, two modules can import the same module under two different prefixes without any conflict at all. ## What actually travels on the wire The encodings never treat a prefix as identity: - **XML (NETCONF)** qualifies elements by namespace URI. An XML namespace prefix appears in the document, but it is just an XML alias; RFC 7950 asks clients and servers to use the module's own prefix there for readability, unless that conflicts. - **JSON (RFC 7951)** qualifies a member name with the **module name**: `"ietf-interfaces:interfaces"`. Data defined in a submodule takes the name of the module it belongs to. - **RESTCONF (RFC 8040)** builds resource paths from the same `module-name:identifier` form. So "the prefix is what identifies my data" is wrong in every encoding, and a client that matches XML elements by prefix rather than by namespace URI breaks as soon as a server uses a different XML prefix. ## The rest of the header A complete header also carries meta-information and history: - `organization`, `contact` and `description` — optional in the grammar, but RFC 9907 requires all three in published modules. - `revision` statements, newest first, each dated `YYYY-MM-DD` — the module's version history. - `import` and `include` — the linkage to other modules and to the module's own submodules. ## Common mistakes - Treating the prefix as globally registered identity. IANA's registry records a module's prefix, but an importer may still choose another. - Assuming the namespace can be "bumped" to signal a new version — the revision date does that; the namespace stays. - Forgetting that a submodule has no namespace or prefix of its own: its definitions live in the namespace of the module it belongs to.

  • Why does RFC 7950 forbid changing a published module's namespace but allow changing its prefix?
    Every encoded instance depends on the namespace: XML elements are qualified by it, so a new URI would turn existing data into another module's data. The prefix lives only inside the module's own text, so §11 allows changing it as long as every local use is changed too; importers never depended on it because they choose their own.
  • Two modules you import both declare the prefix `ex`; what must your module do?
    Import at least one of them under a different prefix. RFC 7950 §7.1.4 says the module's own prefix SHOULD be reused on import unless there is a conflict, and that all prefixes within one module or submodule MUST be unique, so a clash is resolved locally without touching either imported module.

saying these in an interview costs you the question

  • The prefix is the module's global identity and cannot be changed by importers.
  • JSON-encoded YANG data qualifies member names with the module's prefix.
  • You bump the namespace URI to publish a new version of a module.
  • A submodule declares its own namespace for the definitions it contributes.
  • yang-version is optional in YANG 1.1 and defaults to the newest version.
open as a page

In YANG, what is the difference between a container, a list, a leaf and a leaf-list when modelling a router's interfaces?

level: juniorimportance: must knowfreq 30%

basics

~20 s

A YANG leaf holds one typed value and a leaf-list a set of values of one type; a container groups child nodes and occurs at most once under its parent, while a list holds many entries, each identified by its key leafs.

open as a page

In YANG, how does a vendor module use augment to add a QoS leaf to the standard ietf-interfaces list without editing that module?

level: middleimportance: must knowfreq 16%

basics

~10 s

The vendor module imports ietf-interfaces and declares augment "/if:interfaces/if:interface" with the new leaf inside. The leaf appears in every interface entry but belongs to the vendor module's namespace, so the standard module stays untouched.

open as a page

In YANG, how does a must statement differ from a when statement, and what happens to the data when each evaluates to false?

level: middleimportance: must knowfreq 22%

basics

~20 s

A false YANG must is a validation error: the edit is refused with the must's error-message and error-app-tag. A false when means its node does not apply: writes to it fail, and an existing instance is silently deleted.

open as a page

In YANG, how do feature and if-feature make part of a module optional, and what happens when a client configures an unsupported part?

level: middleimportance: must knowfreq 15%

basics

~20 s

A feature statement names an optional capability and if-feature ties schema nodes to it. Where a server does not support the feature those nodes are absent from its schema, and a NETCONF server must reject data for them with unknown-element.

open as a page

In YANG, how does import differ from include, and what does a submodule's belongs-to statement tie it to?

level: middleimportance: must knowfreq 22%

basics

~20 s

In YANG, import references another module's definitions through a local prefix while that module keeps its own namespace; include merges one of the module's own submodules into it. A submodule's belongs-to names the single module it is part of.

open as a page

In YANG, what does config false mean on an interface's counters, and why can a NETCONF client not write them?

level: middleimportance: must knowfreq 22%

basics

~20 s

In YANG, config false marks state data: values the device reports, such as counters and oper-status. State nodes belong to no configuration datastore, so a NETCONF edit has nothing to write them into; clients read them instead.

open as a page

How does a YANG leafref such as the interface-ref typedef keep a reference to an existing interface valid, and what does require-instance false change?

level: middleimportance: must knowfreq 14%

basics

~20 s

A leafref takes the value space of the leaf its path names; with require-instance true, the default, a matching instance must also exist, so removing a referenced interface fails. False keeps the type but drops the existence check.

open as a page

When a YANG typedef or leaf derives from another typedef, how may it narrow range, length and pattern, and why can it never widen them?

level: middleimportance: must knowfreq 15%

basics

~20 s

A derivation may only shrink the value space: a new range or length must be equally or more limiting, every base pattern still applies with new ones ANDed, and an inherited default that no longer fits must be replaced.

open as a page

A device advertising the YANG module ietf-interfaces accepts an edit but silently ignores one leaf; what should it have declared, and why is silence worse?

level: seniorimportance: must knowfreq 14%

basics

~20 s

The device should have shipped a YANG deviation, in a separate module, marking that leaf not-supported or narrowed. A declared gap lets automation adapt before pushing; a silent one leaves intent and device diverging with every edit reporting success.

open as a page

In a YANG module, how do rpc and notification statements differ from the container and leaf data nodes the module defines?

level: juniorimportance: should knowfreq 13%

basics

~10 s

Data nodes describe datastore contents, configuration and state. An rpc defines an operation with optional input and output trees, and a notification defines an event the server sends; neither is stored in a datastore.

open as a page

In a YANG data model, what do the mandatory, min-elements and max-elements statements require of a valid configuration?

level: juniorimportance: should knowfreq 15%

basics

~20 s

In YANG, mandatory true makes a leaf or choice required wherever its parent context exists, while min-elements and max-elements bound how many entries a list or leaf-list holds. The server rejects configuration that breaks them.

open as a page

In a YANG model, what does typing a VLAN ID leaf as uint16 with range "1..4094" buy you over a plain string?

level: juniorimportance: should knowfreq 18%

basics

~10 s

The type fixes the leaf's value space, so any client holding the module can reject 0, 4095 or "ten" before sending, and the server must refuse them too; a plain string accepts all three.

open as a page

What do YANG's four deviate arguments, not-supported, add, replace and delete, each change, and which precondition does each carry?

level: middleimportance: should knowfreq 10%

basics

~20 s

not-supported removes the target node; add attaches properties a single-valued slot must not already hold; replace swaps properties that must exist; delete removes properties whose keyword and argument match exactly. The deviated model must remain valid.

open as a page

Why must every published change to a YANG module add a new revision statement, while its name and namespace stay fixed?

level: middleimportance: should knowfreq 14%

basics

~20 s

A YANG module's revision date is its version: importers pin it and servers report it, so each published change needs a new, later date. Name and namespace are permanent identity; an incompatible change needs a new identifier.

open as a page

Why does YANG require a key on a configuration list, and what changes when a state list has none?

level: middleimportance: should knowfreq 15%

basics

~20 s

A YANG configuration list needs a key because every edit must name the exact entry it touches, and the key leafs' combined values are that name. A state list may omit the key, but then no single entry can be addressed.

open as a page

In an RFC 8340 YANG tree diagram, what do the markers rw, ro, *, ?, ! and [name] tell you about a node?

level: middleimportance: should knowfreq 12%

basics

~20 s

In an RFC 8340 YANG tree diagram, rw marks configuration and ro state; * marks a list or leaf-list and [name] that list's key; ? marks an optional leaf, choice, anydata or anyxml; ! marks a presence container.

open as a page

For a YANG operation that clears one interface's counters, why might a model designer choose a YANG 1.1 action on the interface entry over a top-level rpc?

level: seniorimportance: should knowfreq 11%

basics

~20 s

An action is bound to the interface entry: the path names the target, the entry must exist, and NACM authorises per interface. An rpc takes the interface as a parameter NACM cannot filter, but can cover many interfaces at once.

open as a page

Why does YANG 1.1 require an augment that adds a mandatory configuration leaf to another module's list to carry a when condition, and what breaks without one?

level: seniorimportance: should knowfreq 9%

basics

~20 s

An unconditional mandatory leaf makes every create by a client that knows only the standard module fail validation. YANG 1.1 allows it only under a when that an unaware client never satisfies, such as a vendor-defined interface type.

open as a page

A NETCONF client stages a BGP neighbour with no remote AS in the candidate datastore; when does the server enforce the YANG must and mandatory rules, and what does the client see?

level: seniorimportance: should knowfreq 12%

basics

~20 s

For the candidate datastore, YANG must, mandatory, unique and min/max-elements are checked at commit or validate, not on each edit-config; type, key and when errors surface while the payload is parsed. Running is validated after every edit.

open as a page

An automation repository cannot compile a vendor's YANG module because an imported module is missing; how do you resolve its dependency graph?

level: seniorimportance: should knowfreq 12%

basics

~20 s

Walk the YANG module's import and include statements recursively, collecting every module and submodule. A revision-date demands that exact revision; an unpinned import may resolve to any revision, so supply one that defines everything referenced, before compiling.

open as a page

Why does the IETF YANG ACL model (RFC 8519) key its rules by name yet mark them ordered-by user, and what changes for a client?

level: seniorimportance: should knowfreq 10%

basics

~20 s

In YANG, ordered-by user makes the server keep list entries in the order the client sets, which an ACL needs because the first matching rule decides; keying rules by name keeps each rule's identity stable while its position changes.

open as a page

When a YANG value set such as interface types must grow across modules and vendors, why choose identity and identityref over an enumeration?

level: seniorimportance: should knowfreq 10%

basics

~20 s

An enumeration's names belong to the one module that defines it, so only that module's next revision can add one; any module can derive a new identity from a published base, so an identityref accepts values its author never saw.

open as a page

How should a multi-vendor estate choose between IETF YANG, OpenConfig and vendor-native models for automation, and where do deviations fit in that choice?

level: principalimportance: should knowfreq 9%

basics

~20 s

Prefer a standard model, IETF or OpenConfig, where every platform implements it with few deviations; fall back to vendor-native models where coverage matters more than portability. Track each platform's deviations and features as the measured cost of that choice.

open as a page

In YANG, which node does a when on an augment evaluate against, and what happens to augmented configuration once it turns false?

level: middleimportance: nice to knowfreq 6%

basics

~20 s

A when on an augment is evaluated with the augment's target instance as context node, such as each interface entry. If an edit makes it false, the server silently deletes the augmented nodes; later writes to them get unknown-element.

open as a page

In a YANG list, how does a unique statement differ from the list's key, and which entries does unique leave out of the check?

level: middleimportance: nice to knowfreq 8%

basics

~20 s

A YANG list key identifies each entry and every key leaf must be set; unique adds a rule that the combined values of named leafs differ across entries. Entries missing any referenced leaf, with no default in use, are skipped.

open as a page

In YANG 1.1 conformance, what is the difference between a server implementing a module and only importing it?

level: middleimportance: nice to knowfreq 7%

basics

~20 s

Implementing a module means serving its data nodes, RPCs, actions, notifications and deviations. Importing it only means other modules use its reusable definitions such as typedefs and groupings; none of its own objects are served. Only one revision may be implemented.

open as a page

In a YANG must expression on a BGP neighbour list entry, what is the XPath context node, and why does a predicate need current()?

level: seniorimportance: nice to knowfreq 6%

basics

~20 s

A YANG must's context node is the instance of the node carrying it, where relative paths start. Inside a predicate the context moves to each filtered node; current() returns the original node, so the predicate can use the neighbour's own leafs.

open as a page

Two YANG modules in one toolchain import different revisions of the same module; when is that legal, and what goes wrong?

level: seniorimportance: nice to knowfreq 7%

basics

~20 s

It is legal: each YANG importer takes typedefs, groupings and identities from the revision it pins. But a server implements only one revision, so schema nodes come from that one, and same-named types can differ in value space.

open as a page

In YANG, when two modules reuse one interface-counters grouping through uses, whose namespace do the nodes get, and what can refine change?

level: seniorimportance: nice to knowfreq 6%

basics

~20 s

In YANG, uses copies a grouping's nodes into the schema tree where it appears, bound to that module's namespace; refine then adjusts properties such as default, description, config, mandatory, presence, must, element counts or if-feature, but never a node's type.

open as a page

showing 1–30 of 31