netplan + networkctl
netplan is Ubuntu's YAML network configuration front end (default since 18.04); networkctl is the systemd tool that shows and controls the links managed by systemd-networkd. Together they cover how a modern Ubuntu server gets its IP, routes and DNS.
27.1 How it works: the netplan pipeline
- You write YAML in /etc/netplan/*.yaml (package netplan.io).
- netplan generate turns it into backend files: /run/systemd/network/ for renderer networkd (servers) or NetworkManager (desktops).
- netplan itself runs no daemon; systemd-networkd actually configures the links, and networkctl talks to networkd.
- Linux only; not on Windows or macOS.
- Step 1
1.YAML: /etc/netplan/*.yaml
- Step 2
2.netplan generate: YAML to backend files
- Step 3
3.Backend files in /run/systemd/network/
- Step 4
4.systemd-networkd (or NetworkManager) reads them
- Step 5
5.Kernel links: eth0 gets IP, routes, DNS
apply = generate + backend restart + links up
27.2 YAML file: static IP, gateway, DNS
network: version: 2 renderer: networkd ethernets: eth0: dhcp4: false addresses: [192.168.47.10/24] routes: - to: default via: 192.168.47.1 nameservers: addresses: [8.8.8.8, 1.1.1.1] lan1: dhcp4: false- Indentation matters (spaces, no tabs); keys: version 2, renderer, ethernets, addresses, routes (to: default, via), nameservers.
- The file must be chmod 600, otherwise generate warns 'Permissions ... are too open'.
27.3 netplan sub-commands
| Command | What it does | Useful options |
|---|---|---|
| generate | YAML to backend files only | --mapping IF, --root-dir DIR |
| apply | generate + restart backend + bring links up | --state DIR (removes devices no longer in YAML) |
| try | apply with auto-revert unless you press Enter | --timeout N, --config-file F |
| get | Print the merged YAML or one key | KEY (ethernets.eth0), --root-dir |
| set | Change a key in the YAML | --origin-hint FILE, --root-dir |
| --debug | Global: verbose output | netplan --debug generate |
ls -l /etc/netplan/netplan generatechmod 600 /etc/netplan/01-netcfg.yamlnetplan generatels /run/systemd/network/cat /run/systemd/network/\10-netplan-eth0.networknetplan --debug generate 2>&1 | head -n 8netplan generate --mapping eth0netplan generate --root-dir /mnt/targetls /mnt/target/run/systemd/network/$ ls -l /etc/netplan/-rw-r--r-- 1 root root 271 Nov 8 17:08 01-netcfg.yaml$ netplan generate** (generate:4366): WARNING **: 17:08:55.136:Permissions for /etc/netplan/01-netcfg.yaml are too open.Netplan configuration should NOT be accessible by others.$ chmod 600 /etc/netplan/01-netcfg.yaml$ netplan generate$ ls /run/systemd/network/10-netplan-eth0.network10-netplan-lan1.network$ cat /run/systemd/network/10-netplan-eth0.network[Match]Name=eth0[Network]LinkLocalAddressing=ipv6Address=192.168.47.10/24DNS=8.8.8.8DNS=1.1.1.1[Route]Destination=0.0.0.0/0Gateway=192.168.47.1$ netplan --debug generateDEBUG:command generate: running ['/lib/netplan/generate']** DEBUG: 17:08:56.792: starting new processing pass** DEBUG: 17:08:56.793: eth0: adding new route** DEBUG: 17:08:56.793: Configuration is valid$ netplan generate --mapping eth0id=eth0, backend=networkd, set_name=(null),match_name=eth0, match_mac=(null), match_driver=(null)$ netplan generate --root-dir /mnt/target$ ls /mnt/target/run/systemd/network/10-netplan-eth0.network10-netplan-lan1.network27.4 netplan apply
- apply regenerates and restarts systemd-networkd (here it fell back to a hard restart because D-Bus reload was unavailable).
- Removing a YAML file and running apply does not delete the virtual device (br0 stays); apply --state DIR compares with the old config and removes it.
netplan applynetworkctl list "eth*" "lan*"networkctl list "br*"cp -p /etc/netplan/*.yaml \ /root/state/etc/netplan/rm /etc/netplan/90-br0.yamlnetplan applyip -br link show br0netplan apply --state /root/stateip -br link show br0$ netplan applyFailed to reload network settings: Unit dbus-org.freedesktop.network1.service not found.Falling back to a hard restart of systemd-networkd.service$ networkctl list "eth*" "lan*"IDX LINK TYPE OPERATIONAL SETUP 9 eth0 ether routable configured 11 lan1 ether no-carrier configuring2 links listed.$ networkctl list "br*"IDX LINK TYPE OPERATIONAL SETUP 12 br0 bridge no-carrier configured$ rm /etc/netplan/90-br0.yaml$ netplan apply$ ip -br link show br0br0 DOWN ee:c3:e8:67:52:e7 <NO-CARRIER,BROADCAST,MULTICAST,UP>$ netplan apply --state /root/state$ ip -br link show br0Device "br0" does not exist.27.5 netplan get / set
- get prints the merged config of all YAML files; a dotted key (ethernets.eth0, network.ethernets.eth0.addresses) prints one part.
- set KEY=VALUE writes the YAML for you; --origin-hint=80-lan1 writes into /etc/netplan/80-lan1.yaml.
- set does not apply anything: run netplan apply (or try) afterwards.
netplan getnetplan get ethernets.eth0netplan get network.ethernets.eth0.addressesnetplan get --root-dir=/mnt/target \ ethernets.lan1$ netplan get ethernets.eth0addresses:- "192.168.47.10/24"nameservers: addresses: - 8.8.8.8 - 1.1.1.1dhcp4: falseroutes:- to: "default" via: "192.168.47.1"$ netplan get network.ethernets.eth0.addresses- "192.168.47.10/24"$ netplan get --root-dir=/mnt/target ethernets.lan1dhcp4: falsenetplan set ethernets.lan1.dhcp4=truenetplan get ethernets.lan1netplan set "ethernets.eth0.addresses=\[192.168.47.10/24, 192.168.47.11/24]"netplan set --origin-hint=80-lan1 \ "ethernets.lan1={dhcp4: true, dhcp6: false}"cat /etc/netplan/80-lan1.yamlnetplan set --root-dir=/mnt/target \ ethernets.eth0.dhcp4=truenetplan applyip -4 -br addr$ netplan set ethernets.lan1.dhcp4=true$ netplan get ethernets.lan1dhcp4: true$ ls /etc/netplan/01-netcfg.yaml80-lan1.yaml$ cat /etc/netplan/80-lan1.yamlnetwork: version: 2 ethernets: lan1: dhcp4: true dhcp6: false$ netplan get --root-dir=/mnt/target ethernets.eth0.dhcp4true$ netplan apply$ ip -4 -br addrlo UNKNOWN 127.0.0.1/8eth0 UP 192.168.47.10/24 192.168.47.11/24lan1 UP 192.168.147.135/24 metric 10027.6 netplan try: safe changes over SSH
- Step 1
1.Admin laptop is connected over SSH via the switch to eth0 192.168.47.10
- Step 2
2.netplan try applies the new YAML and starts a countdown
- Step 3
3.SSH still works: press Enter (or SIGUSR1) -> 'Configuration accepted.'
- Step 4
4.SSH is cut: nobody presses Enter
- Step 5
5.Timeout (or SIGINT): 'Reverting.' old config is back
- Step 6
6.SSH works again
With plain apply, a wrong gateway would lock you out
netplan try --timeout 60 \ --config-file /root/test-netplan.yamlip -4 -br addr show eth0kill -USR1 $(pgrep -x netplan)netplan try --timeout 60 \ --config-file /root/bad.yamlkill -INT $(pgrep -x netplan)netplan try --timeout 10 \ --config-file /root/bad.yaml$ netplan try --timeout 60 --config-file /root/test-netplan.yamlDo you want to keep these settings?Press ENTER before the timeout to accept the new configurationChanges will revert in 60 seconds$ ip -4 -br addr show eth0eth0 UP 192.168.47.10/24 192.168.47.11/24 192.168.47.12/24Changes will revert in 59 seconds$ kill -USR1 $(pgrep -x netplan)Configuration accepted.$ netplan try --timeout 60 --config-file /root/bad.yaml$ ip -4 -br addr show eth0eth0 UP 192.168.47.10/24 192.168.99.10/24 ...$ kill -INT $(pgrep -x netplan)Reverting.$ ip -4 -br addr show eth0eth0 UP 192.168.47.10/24 192.168.47.11/24 192.168.47.12/24$ netplan try --timeout 10 --config-file /root/bad.yamlChanges will revert in 10 secondsChanges will revert in 9 secondsChanges will revert in 1 secondsReverting.$ ip -4 -br addr show eth0eth0 UP 192.168.47.10/24 192.168.47.11/24 192.168.47.12/2427.7 networkctl query: list, status, lldp, label, cat
- list [PATTERN]: IDX, LINK, TYPE, OPERATIONAL and SETUP state of every link.
- status: overall state, online state, addresses, gateways, DNS; status IF: details + recent journal lines.
- lldp shows LLDP neighbours; label shows IPv6 address labels; cat @IF prints the .network file used by a link.
networkctl listnetworkctl list "eth*" "lan*"networkctl statusnetworkctl status eth0$ networkctl listIDX LINK TYPE OPERATIONAL SETUP 1 lo loopback carrier unmanaged 2 gre0 ipgre off unmanaged 3 gretap0 ether off unmanaged 5 tunl0 tunnel off unmanaged 6 sit0 sit off unmanaged 9 eth0 ether routable configured 11 lan1 ether degraded configuring10 links listed.$ networkctl status● State: routable Online state: online Address: 192.168.47.10 on eth0 192.168.147.135 on lan1 Gateway: 192.168.47.1 on eth0 192.168.147.1 on lan1 DNS: 192.168.147.1 8.8.8.8$ networkctl status eth0● 9: eth0 Network File: /run/systemd/network/10-netplan-eth0.network State: routable (configured) Type: etherHardware Address: a6:72:c3:e0:60:5a Speed: 10Gbps Address: 192.168.47.10 Gateway: 192.168.47.1 DNS: 8.8.8.8systemd-networkd[4453]: eth0: Configuring with ...10-netplan-eth0.network.networkctl lldpnetworkctl labelnetworkctl cat @eth0networkctl cat 10-netplan-lan1.network$ networkctl lldpLINK CHASSIS-ID SYSTEM-NAME CAPS PORT-ID PORT-DESCRIPTION0 neighbors listed.$ networkctl labelLABEL PREFIX/PREFIXLEN 0 ::1/128 1 ::/0 2 2002::/16 4 ::ffff:0.0.0.0/96 5 fc00::/7 6 2001::/32$ networkctl cat @eth0# /run/systemd/network/10-netplan-eth0.network[Match]Name=eth0[Network]Address=192.168.47.10/24Address=192.168.47.11/24Address=192.168.47.12/24DNS=8.8.8.8$ networkctl cat 10-netplan-lan1.network# /run/systemd/network/10-netplan-lan1.network[Match]Name=lan1[Network]DHCP=ipv4LinkLocalAddressing=ipv6[DHCP]RouteMetric=10027.8 networkctl control: up, down, renew, reload, reconfigure, delete, edit
- up / down bring a link up or down; delete removes a virtual device (vlan10).
- renew asks the DHCP server to extend the lease (server log: 'sending ACK'); forcerenew asks the server to make clients renew.
- reload re-reads .network/.netdev files; reconfigure IF reapplies config to one link.
- edit opens a config file in $SYSTEMD_EDITOR; --drop-in crashed with an assertion in systemd 254 (real result).
- Step 1
1.networkctl renew lan1 on n027-lab
- Step 2
2.networkd sends DHCP REQUEST for the same lease
- Step 3
3.DHCP server 192.168.147.1 (udhcpd) replies ACK
- Step 4
4.Lease time is full again, IP 192.168.147.135 stays
networkctl down lan1networkctl list "lan*"networkctl up lan1networkctl renew lan1tail -n 4 /tmp/udhcpd.lognetworkctl forcerenew lan1networkctl reloadnetworkctl reconfigure eth0networkctl delete vlan10networkctl list "eth*" "vlan*"$ networkctl down lan1$ networkctl list "lan*" 11 lan1 ether off configured$ networkctl up lan1$ networkctl list "lan*" 11 lan1 ether routable configured$ networkctl renew lan1$ tail -n 4 /tmp/udhcpd.logudhcpd: sending OFFER to 192.168.147.135udhcpd: sending ACK to 192.168.147.135udhcpd: sending ACK to 192.168.147.135udhcpd: sending ACK to 192.168.147.135$ networkctl list "eth*" "vlan*" 9 eth0 ether routable configured 13 vlan10 vlan routable configured$ networkctl delete vlan10$ networkctl list "eth*" "vlan*" 9 eth0 ether routable configured1 links listed.export SYSTEMD_EDITOR=/root/ed.shnetworkctl edit --no-reload \ 99-default.linkfind /etc/systemd/network -type fnetworkctl edit --drop-in=mtu @lan1$ networkctl edit --no-reload 99-default.linkSuccessfully installed edited file '/etc/systemd/network/99-default.link'.$ find /etc/systemd/network -type f/etc/systemd/network/99-default.link$ networkctl edit --drop-in=mtu @lan1Assertion '!arg_drop_in || dropins' failed atsrc/network/networkctl.c:3175, function add_config_to_edit(). Aborting.Aborted (core dumped)27.9 networkctl options
- -a all links, -s statistics, -n N journal lines, -l full width, --no-legend, --no-pager.
- --json=short|pretty|off for scripts; -h help; --version (systemd 254 in the lab).
networkctl -a status | head -n 12networkctl -s status lan1networkctl -n 3 status lan1networkctl --no-legend list "eth*" "lan*"networkctl --json=short list | head -c 300networkctl --json=pretty status eth0 \ | head -n 20networkctl --version | head -1$ networkctl -s status lan1 Rx Packets: 43 Tx Packets: 59 Rx Bytes: 9400 Tx Bytes: 12378 Rx Errors: 0 Rx Dropped: 0$ networkctl -n 3 status lan1lan1: Configuring with /run/systemd/network/10-netplan-lan1.network.lan1: DHCPv6 lease lostlan1: DHCPv4 address 192.168.147.135/24, gateway 192.168.147.1 acquired from 192.168.147.1$ networkctl --no-legend list "eth*" "lan*" 9 eth0 ether routable configured 11 lan1 ether routable configured$ networkctl --json=short list | head -c 300{"Interfaces":[{"Index":1,"Name":"lo","Type":"loopback",...$ networkctl --version | head -1systemd 254 (254.26-1~bpo12+1)27.10 Link states
| Type | State | Meaning |
|---|---|---|
| Operational | off / no-carrier | Powered down / up but no cable |
| Operational | dormant / carrier | Carrier, waiting for auth / link up, no IP |
| Operational | degraded / degraded-carrier | Link-local IP only / a bond or bridge port is down |
| Operational | enslaved / routable | Port of a bond/bridge / routable IP, all OK |
| Setup | pending / initialized | udevd still processing / done, no decision yet |
| Setup | configuring / configured / failed | Being applied / success / failed |
| Setup | unmanaged / linger | networkd doesn't handle it / link gone, entry remains |
| Online | online / partial / offline | All required links online / some / none |
networkctl down lan1networkctl status | grep -i "online state"networkctl up lan1networkctl status | grep -i "online state"$ networkctl down lan1$ networkctl status | grep -i "online state" Online state: partial$ networkctl up lan1$ networkctl status | grep -i "online state" Online state: online27.11 Common mistakes
- Editing /run/systemd/network/*.network: generate rewrites them on every boot and apply. Change /etc/netplan/*.yaml or use netplan set.
- Running netplan apply over SSH for a gateway change; use netplan try.
- Leaving the YAML world-readable (chmod 600 it) or using tabs in YAML.
- Expecting a removed YAML to delete its device without apply --state.
27.12 Interview tips
- netplan = front end (YAML to backend files, no daemon); systemd-networkd = daemon that configures links; networkctl = client of networkd.
- Remote change: netplan try (auto-revert on timeout, Enter = keep).
- Source of truth is /etc/netplan; /run is generated.
- networkctl status IF shows which .network file a link uses and its operational/setup state.