systemd-networkd is the network manager that ships inside systemd. It reads plain-text INI unit files from /etc/systemd/network: a .network file decides what happens to the links it matches — addresses, routes, DHCP behaviour, enslavement to a master — a .netdev file creates a virtual device such as a bond, a VLAN or a bridge, and a .link file, applied by systemd-udevd rather than by the daemon, renames or reconfigures the device itself before any of that. The networkctl command exposes the running state: reload the files, reconfigure a link, bring one up or down, renew a lease. On Ubuntu server it is the backend netplan renders into, which means even hosts that "use netplan" end their configuration journey in exactly these unit files.

Reemote is a pure-Python configuration-management library. Instead of a domain-specific language, you write an ordinary Python generator that yields operations against a host, gather typed facts from the target, and await a two-phase run that previews the whole plan before it changes anything. The systemd_networkd module is written in that spirit: it owns the unit files under /etc/systemd/network and the networkctl calls that act on them, and nothing else. It needs no agent, no interpreter and no template file on the managed machine — only the systemd every Linux distribution already ships, plus a POSIX shell and an SSH connection.

This article builds a set of examples that write static units, pin down DHCP lease behaviour, stage a .link file and layer a bond, a VLAN and a bridge over them, then read the daemon back, drive it directly and clean up — and runs every one of them against a persistent Ubuntu host.

Try the canonical example first

Install Python 3.13 or newer and Docker or Podman. The connector requires you to name the CLI explicitly; there is no default.

uv venv .venv source .venv/bin/activate uv pip install reemote 

Save this as hello.py. It is the canonical example configured for Podman. The offline pytest suite simulates the connector, and the example was also verified live with Podman. Change both docker_cmd values to "docker" if that is your local CLI.

# hello.py import asyncio from reemote import files, format_log, format_plan, op, run INVENTORY = [ { "host": "demo0", "family": "Alpine", "connection": { "connector": "docker", "identifier": "alpine:3.20", "docker_cmd": "podman", }, }, { "host": "demo1", "family": "Alpine", "connection": { "connector": "docker", "identifier": "alpine:3.20", "docker_cmd": "podman", }, }, ] def deploy(host): yield op( files.install, name="Write a greeting", content="Hello from reemote!\n", dest="/tmp/reemote-hello.txt", mode="0644", ) yield op( files.install, name="Record the host name", content=f"written on {host.name}\n", dest="/tmp/reemote-host.txt", mode="0644", ) async def main(): plans, report, _ = await run(INVENTORY, deploy, dry=True) print("== Dry run ==") print(format_plan(plans)) assert report is None _, report, _ = await run(INVENTORY, deploy) print("\n== Applied ==") assert report is not None print(format_log(report)) asyncio.run(main()) 

Run it with python hello.py. The dry run connects to both containers and reads real state, but sends no mutating deploy commands inside them. The connector may still create, commit, and remove its temporary containers. The apply then advances through the two operations in lockstep: both hosts finish writing the greeting before either starts recording its name.

Verified output from Podman is shown below. The dry-run plan is host-major, while the apply log is step-major: both Write a greeting entries appear before either Record the host name entry.

== Dry run == demo0: Write a greeting [changed: content /tmp/reemote-hello.txt is absent, will install] demo0: Record the host name [changed: content /tmp/reemote-host.txt is absent, will install] demo1: Write a greeting [changed: content /tmp/reemote-hello.txt is absent, will install] demo1: Record the host name [changed: content /tmp/reemote-host.txt is absent, will install] == Applied == demo0: Write a greeting [changed: content /tmp/reemote-hello.txt is absent, will install] $ scp <files install> -> /tmp/reemote-install-2e52d4f8373a608a/content $ sh -c 'mkdir -p /tmp && cp /tmp/reemote-install-2e52d4f8373a608a/content /tmp/reemote-hello.txt && chmod 644 /tmp/reemote-hello.txt && rm -rf /tmp/reemote-install-2e52d4f8373a608a' demo1: Write a greeting [changed: content /tmp/reemote-hello.txt is absent, will install] $ scp <files install> -> /tmp/reemote-install-2e52d4f8373a608a/content $ sh -c 'mkdir -p /tmp && cp /tmp/reemote-install-2e52d4f8373a608a/content /tmp/reemote-hello.txt && chmod 644 /tmp/reemote-hello.txt && rm -rf /tmp/reemote-install-2e52d4f8373a608a' demo0: Record the host name [changed: content /tmp/reemote-host.txt is absent, will install] $ scp <files install> -> /tmp/reemote-install-8c7265455d37e471/content $ sh -c 'mkdir -p /tmp && cp /tmp/reemote-install-8c7265455d37e471/content /tmp/reemote-host.txt && chmod 644 /tmp/reemote-host.txt && rm -rf /tmp/reemote-install-8c7265455d37e471' demo1: Record the host name [changed: content /tmp/reemote-host.txt is absent, will install] $ scp <files install> -> /tmp/reemote-install-8c7265455d37e471/content $ sh -c 'mkdir -p /tmp && cp /tmp/reemote-install-8c7265455d37e471/content /tmp/reemote-host.txt && chmod 644 /tmp/reemote-host.txt && rm -rf /tmp/reemote-install-8c7265455d37e471' 

An image identifier creates a throwaway container for each host. On close, Reemote commits it to a new image and removes the container. That makes every run start fresh; idempotence is demonstrated later against an existing container instead.

Unlike the throwaway-container quickstart, the migration examples below reuse the same Ubuntu hosts, so repeated runs demonstrate convergence against persistent host state.

How systemd-networkd configures a link

A unit file is short enough to read at a glance — an optional header comment, a [Match] section that selects links, and the sections that describe what to do with them:

[Match] Name=eth1 [Network] Address=10.30.0.11/24 Gateway=10.30.0.1 DHCP=no 

Five properties of that arrangement decide how an automation tool has to treat it.

  • One directory holds three kinds of file. A .network file configures links that already exist. A .netdev file creates a virtual device: [NetDev] Kind=bond (or vlan, bridge) plus the kind's own section — [Bond], [VLAN], [Bridge]. A .link file is not read by networkd at all: it belongs to systemd-udevd, renames the device and sets its MAC and MTU at udev time, before any .network can match the new name. A tool that manages all three has to know which writes a reload actually picks up, and which it does not.
  • Files match links; they do not name them. [Match] selects interfaces by Name=, Path=, MACAddress=, Type= and more. Every matching .network applies to a link, and when several files match the same one their settings merge in filename order — which is why units carry numeric prefixes. There is no single "configuration for eth1"; there is a set of files, each of which may claim a set of links.
  • The daemon reads when you tell it to. Dropping a file into /etc/systemd/network changes nothing until networkctl reload re-reads the units and reconfigures every link they match. networkctl reconfigure <link> pushes the already-loaded configuration onto one named link without re-reading any file; networkctl up/down flip the kernel's IFF_UP flag; networkctl renew asks the DHCP server for a fresh lease. None of this restarts the daemon, and none of it needs daemon-reload — networkd notices its own files through inotify, but reload is the deterministic verb.
  • Reading needs no root; writing does. Unit files are conventionally root:root mode 0644, so an unprivileged login can list and read everything in /etc/systemd/network while every change goes through the escalation tool. That is the opposite of netplan's 0600 drop-ins, and it means the facts here are cheap.
  • On Ubuntu, netplan renders into /run. netplan generate writes backend unit files into the volatile /run/systemd/network, which is wiped at every boot and which networkctl happily matches links against. The directory this article's module owns — /etc/systemd/network — is the hand-managed one, and the two coexist; a .network that matches an interface netplan already claims competes with the rendered file, so every example here matches interfaces the vendor configuration does not claim.

The systemd.network(5) manual page covers the grammar in full, and the references at the end list the further reading this article's shape follows.

The Reemote systemd_networkd module

The systemd_networkd module answers the four questions worth asking about a host, and each answer is one fact. NetworkdUnits lists every unit under /etc/systemd/network as filename to kind/path/mode in a single shell round trip. NetworkdUnitFile returns one named file's raw text — byte-exact, absent distinguished from empty — and it is the read-back every write is judged against. NetworkdLinks projects networkctl list --json=short into per-interface rows: the administrative and operational states, the kernel up flag, the MAC, the addresses in CIDR form, and the .network file the link actually matched — which on a netplan host lives under /run/systemd/network, so you can see which rendered file won even though the module does not manage it. NetworkdConfig flattens the effective networkd.conf plus drop-ins into Section.Key values; on an untouched host it reads empty, because the stock file comments every row out. None of the four needs elevation.

Its operations are one write family and three verbs. network_unit owns a single unit file by bare name: it compares the wanted text against what NetworkdUnitFile reads back, and only on a real difference spools the content to a /tmp directory as the login user and installs it in one elevated step as root:root mode 0644 — then follows the write with networkctl reload, chained by the operation itself and only for .network and .netdev kinds, with reload=False available when a group of files should be reloaded once at the end. link_state reconciles a link's kernel up flag with networkctl up/down, reporting a change only when the flag differs, and refusing to guess about an interface the host does not report. reload and reconfigure_links are stateless remediation: they read no fact, always report a change and always yield their command, because "these links already have these files" is not cheap to observe. Removing a unit is the same write with present=False: one rm -f, the same reload chaining, the same read-back gate.

Three boundaries matter when composing it. The module does not own the daemon: systemd-networkd.service is an ordinary unit, so enabling and starting it belongs to the systemd module. The module never touches a competing manager: stopping NetworkManager on a live host can re-address the interface carrying your session, and that decision stays yours to make explicitly. And if what you actually want to edit is the host's netplan YAML, the netplan module is the right tool — this one exists for the units you write yourself.

Managing network services from Python

A playbook that manages these units has a fixed shape: render a template, notify a handler, ensure the daemon, gather state afterwards. Each piece has a direct counterpart in a Reemote deploy:

  • Writing a finished unit from a string: op(systemd_networkd.network_unit, filename=..., content=..., sudo=True).
  • Building that text from a table of options instead of a template file: an ordinary Python function, then the same request.
  • Managing a group of units in one deploy: a loop yielding one request per file, reload=False on all but the last.
  • The "notify the reload handler" step: the chained reload, which fires only if the bytes actually changed.
  • Removing a unit: the same request with present=False.
  • Enabling the daemon itself: op(systemd.service, service="systemd-networkd", running=True, enabled=True, sudo=True).
  • Bringing a link up, re-reading units, renewing a lease: link_state, reload, reconfigure_links(renew=True).
  • Reading what a host holds: the four facts, with gather_fact across the fleet.
  • Skipping hosts of another family: when=is_ubuntu on the request.
  • Checking what would change before touching the network: that is what the dry=True phase of every run already is.

Two conventions carry through every example below. Arguments passed to op() must stay hashable, so tables are tuples of tuples and unit bodies are plain strings; and the escalation flag belongs to the request (sudo=True) while the run-as user stays a property of the inventory. The when=is_ubuntu guard means a mixed fleet skips non-Ubuntu hosts instead of failing on them.

Inventory for the systemd_networkd host

The examples use the repository's real Ubuntu SSH host. Save an equivalent inventory as inventory.json:

[ { "host": "ubuntu", "family": "Ubuntu", "connection": { "connector": "ssh", "address": "192.168.0.251", "port": 22, "username": "supervisor", "key_path": "~/.ssh/id_ed25519" }, "tags": ["ubuntu_host", "apt_package_manager"] } ] 

Replace the address, user and key path with your own. Every managed write lands under /etc/systemd/network, so the login needs passwordless sudo; verify the host key and populate ~/.ssh/known_hosts rather than disabling host-key checking, as the SSH connector reference describes. Look at what the host already has before you start, because the generated units under /run tell you which links networkd already claims:

ssh supervisor@192.168.0.251 'ls -l /etc/systemd/network; networkctl list' 

Runnable examples for the inventory Ubuntu host

Clone the repository and edit its inventory.json, or replace that file with the inventory above:

git clone https://github.com/kimjarvis/reemote.git cd reemote 

The scripts under examples/articles/systemd_networkd/ load that inventory, select only entries whose family is Ubuntu, and use sudo for the root-owned state. Mutating scripts preview by default and require --apply; the inspection script is read-only. They share one helper, systemd_networkd_article_common.py, which holds the managed-unit list and the preview/apply driver.

Example Article concept
systemd_networkd_hello.py The canonical two operations against persistent SSH hosts
systemd_networkd_service.py Keep the daemon running and enabled with the systemd module
systemd_networkd_static.py One static IPv4 .network unit with a chained reload
systemd_networkd_rendered.py Render units from a Python table instead of a template
systemd_networkd_dhcp.py DHCP lease behaviour, plus a .link file no reload reads
systemd_networkd_bond.py A bond, a VLAN and a bridge across .netdev and .network pairs
systemd_networkd_inspect.py Read back units, links and configuration; --check gate
systemd_networkd_activate.py link_state, reload and lease renewal on a live link
systemd_networkd_cleanup.py Remove every unit the article manages

Every example names interfaces the lab host does not have — eth1 through eth4, lab0, lab1, lan99 — and every virtual device it creates (rmbond0, rmvlan110, rmbr0) comes up with no members and no route to anywhere, so the files can be applied repeatedly on a machine you are logged into, and the cleanup script takes the whole set back down again. The only example that acts on a live link is systemd_networkd_activate.py, and its default interface is lo. Point a [Match] at a real interface only on a host you can reach out of band.

Run a read-only preview from the repository root:

uv run python examples/articles/systemd_networkd/systemd_networkd_static.py 

Run the canonical pair on a real host

The first script is the quickstart's two files.install operations, kept as the article's baseline against a persistent host: same requests, same preview-then-apply shape, SSH instead of a container, and a family guard so a RedHat host in the same inventory is skipped rather than failing.

# systemd_networkd_hello.py # Copyright (c) 2026 Kim Jarvis. # SPDX-License-Identifier: EPL-2.0 """Run the canonical two operations against persistent Ubuntu SSH hosts.""" import asyncio import sys from pathlib import Path from reemote import files, op sys.path.insert(0, str(Path(__file__).resolve().parent)) from systemd_networkd_article_common import ( execute, is_ubuntu, load_inventory, parser, ) def deploy(host): yield op( files.install, name="Write a greeting", content="Hello from reemote!\n", dest="/tmp/reemote-hello.txt", mode="0644", when=is_ubuntu, ) yield op( files.install, name="Record the host name", content=f"written on {host.name}\n", dest="/tmp/reemote-host.txt", mode="0644", when=is_ubuntu, ) async def main(argv=None): args = parser(__doc__).parse_args(argv) await execute(load_inventory(args.inventory), deploy, apply_changes=args.apply) if __name__ == "__main__": asyncio.run(main()) 

The preview reads the host and reports what it would write, without sending a mutating command:

== Preview == ubuntu: Write a greeting [changed: content /tmp/reemote-hello.txt is absent, will install] ubuntu: Record the host name [changed: content /tmp/reemote-host.txt is absent, will install] Preview only; pass --apply to change the hosts. 

Keep the daemon running and enabled

A playbook that manages .network units starts by making sure the daemon that reads them is actually up. Reemote deliberately does not wrap that work inside systemd_networkd — systemd-networkd.service is an ordinary unit, and the systemd module already owns it — so this example is two plain service requests: the daemon running and enabled, and the oneshot boot waiter enabled without any claim about its running state (running=None, because a oneshot unit is never "running" the way a daemon is).

# systemd_networkd_service.py # Copyright (c) 2026 Kim Jarvis. # SPDX-License-Identifier: EPL-2.0 """Keep the networkd daemon itself running and enabled with ``systemd.service``. A playbook that manages ``.network`` units starts by making sure the daemon that reads them is actually up, and stops whichever competing manager the distribution shipped. Reemote deliberately does not wrap that work inside ``systemd_networkd``: ``systemd-networkd.service`` is an ordinary systemd unit, so the ``systemd`` module already owns it, and re-wrapping ``enabled``/``running`` under a second name would only hide that. The example asks for two things: * ``systemd-networkd.service`` running and enabled at boot — the daemon that reads ``/etc/systemd/network`` and answers ``networkctl``; * ``systemd-networkd-wait-online.service`` enabled only (``running=None``): it is a oneshot boot waiter, so it is never "running" the way a daemon is, and managing its boot membership is the whole job. Both requests are idempotent reads of ``SystemdServiceState`` / ``SystemdServiceEnabled``: on a converged host each reports ``no change`` and sends nothing. **The example never touches NetworkManager.** A host that renders its networking with NetworkManager is not a host to hand over to networkd from an SSH session — stopping the current manager can re-address the interface carrying the session. The lab hosts here already run networkd (Ubuntu server renders with netplan's networkd backend), so this script only proves the daemon is up before the unit-file examples run. """ import asyncio import sys from pathlib import Path from reemote import op, systemd sys.path.insert(0, str(Path(__file__).resolve().parent)) from systemd_networkd_article_common import ( execute, is_ubuntu, load_inventory, parser, ) def deploy(host): yield op( systemd.service, name="Run systemd-networkd", service="systemd-networkd", running=True, enabled=True, sudo=True, when=is_ubuntu, ) yield op( systemd.service, name="Enable the boot wait-online unit", service="systemd-networkd-wait-online", running=None, enabled=True, sudo=True, when=is_ubuntu, ) async def main(argv=None): args = parser(__doc__).parse_args(argv) await execute(load_inventory(args.inventory), deploy, apply_changes=args.apply) if __name__ == "__main__": asyncio.run(main()) 

The apply shows the commands the two requests expand into — one start and two enable calls:

== Applied == ubuntu: Run systemd-networkd [changed: systemd-networkd.service not running (None), will start; systemd-networkd.service not enabled, will enable] $ sudo systemctl start systemd-networkd.service $ sudo systemctl enable systemd-networkd.service ubuntu: Enable the boot wait-online unit [changed: systemd-networkd-wait-online.service active state left alone; systemd-networkd-wait-online.service not enabled, will enable] $ sudo systemctl enable systemd-networkd-wait-online.service 

A second pass reads the same two facts and sends nothing:

== Applied == ubuntu: Run systemd-networkd [no change: systemd-networkd.service already running; systemd-networkd.service already enabled] ubuntu: Enable the boot wait-online unit [no change: systemd-networkd-wait-online.service active state left alone; systemd-networkd-wait-online.service already enabled] 

The example never touches NetworkManager, and neither should you from an SSH session: a host that renders its networking with NetworkManager is a host where stopping the current manager can re-address the interface carrying your connection. The lab host already runs networkd, so this script only proves the daemon is up before the unit-file examples run.

Write one static IPv4 unit

One network_unit request is the whole static-IP story: a complete INI document for a named unit file. The operation compares that text byte for byte against the NetworkdUnitFile read-back — the trailing newline is part of the contract — so the template file, the handler and the "restart if changed" notification collapse into a single request, and the reload that follows in the transcript below is there only because the bytes actually changed.

# systemd_networkd_static.py # Copyright (c) 2026 Kim Jarvis. # SPDX-License-Identifier: EPL-2.0 """Write one static-IPv4 ``.network`` unit with ``systemd_networkd.network_unit``. The example manages ``/etc/systemd/network/60-reemote-eth1.network``: a whole INI document handed to the operation as a plain string. ``network_unit`` reads the file back through ``NetworkdUnitFile`` and compares **byte for byte** — the trailing newline is part of the contract — so a template file, a handler and a "restart if changed" notification all collapse into one request: the reload is *chained by the operation itself*, and only on a real change. The unit gives an interface a static address, a gateway, two resolvers and a search domain — the same content a Jinja ``10-eth0.network.j2`` template would render:: [Match] Name=eth1 [Network] Address=10.30.0.11/24 Gateway=10.30.0.1 DNS=1.1.1.1 DNS=9.9.9.9 Domains=lab.example **Nothing here touches the interface carrying the session.** The ``[Match]`` names ``eth1``, which the lab host does not have, so the chained ``networkctl reload`` re-reads every unit file — including netplan's rendered copies under ``/run/systemd/network`` — and reconfigures no live link. Point a ``Name=`` at a real interface only on a machine you can reach out of band: changing the address or default route of the link carrying your SSH session drops it. Run it with:: uv run python examples/articles/systemd_networkd/systemd_networkd_static.py uv run python examples/articles/systemd_networkd/systemd_networkd_static.py --apply """ import asyncio import sys from pathlib import Path from reemote import op, systemd_networkd sys.path.insert(0, str(Path(__file__).resolve().parent)) from systemd_networkd_article_common import ( STATIC_UNIT, execute, is_ubuntu, load_inventory, parser, ) STATIC_CONTENT = ( "# Managed by Reemote. Do not edit by hand.\n" "[Match]\n" "Name=eth1\n" "\n" "[Network]\n" "Address=10.30.0.11/24\n" "Gateway=10.30.0.1\n" "DNS=1.1.1.1\n" "DNS=9.9.9.9\n" "Domains=lab.example\n" "\n" "[Link]\n" "MTUBytes=9000\n" ) def deploy(host): yield op( systemd_networkd.network_unit, name="Configure a static IPv4 address on eth1", filename=STATIC_UNIT, content=STATIC_CONTENT, sudo=True, when=is_ubuntu, ) async def main(argv=None): args = parser(__doc__).parse_args(argv) await execute(load_inventory(args.inventory), deploy, apply_changes=args.apply) if __name__ == "__main__": asyncio.run(main()) 

The content is what a template would have rendered:

# Managed by Reemote. Do not edit by hand. [Match] Name=eth1 [Network] Address=10.30.0.11/24 Gateway=10.30.0.1 DNS=1.1.1.1 DNS=9.9.9.9 Domains=lab.example [Link] MTUBytes=9000 

Review the plan, then apply it. The preview names the file and the reason it collected:

== Preview == ubuntu: Configure a static IPv4 address on eth1 [changed: networkd unit /etc/systemd/network/60-reemote-eth1.network miss...
Source:https://dev.to/kimbofab/use-systemdnetworkd-to-manage-network-services-in-python-l3i