Skip to main content
RunBook Academy

← All labs in Linux

Lab · intermediate · ~45 min

Lab: Configure a static address with Netplan and verify it

B · Nested virtualisationC · Simulation

Objectives

  • Write a Netplan YAML file for a static IPv4 and IPv6 configuration
  • Apply the configuration safely with netplan try
  • Verify the result with networkctl and ip
  • Test end-to-end connectivity after the change

Prerequisites

This lab writes a Netplan configuration, applies it, and verifies the result end-to-end. It is the canonical exercise for any host that needs a static IP.

Objective

By the end of this lab, you can:

  • Write a Netplan YAML that sets a static IPv4 and IPv6 address, default route, and DNS servers.
  • Apply it safely with netplan try.
  • Verify the change with networkctl and ip.
  • Roll back if anything goes wrong.

Architecture

The host is on a network with these parameters:

  • Interface: eth0.
  • Static IPv4: 10.10.0.50/24.
  • Static IPv6: 2001:db8:10:10::50/64.
  • Default gateway IPv4: 10.10.0.1.
  • Default gateway IPv6 (link-local): fe80::1.
  • DNS: 1.1.1.1 and 8.8.8.8.
  • Search domain: lab.local.

The host’s current configuration is DHCP. You are replacing it with static.

Tasks

Task 1: Read the existing configuration

ls /etc/netplan/
cat /etc/netplan/*.yaml
ip addr show eth0
ip route show
cat /etc/resolv.conf
systemctl status systemd-networkd

Write down the current addresses, routes, and DNS servers. You will compare against the new configuration.

Task 2: Write the new configuration

Create /etc/netplan/99-static.yaml (the high prefix means it overrides earlier files):

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: no
      dhcp6: no
      addresses:
        - 10.10.0.50/24
        - 2001:db8:10:10::50/64
      routes:
        - to: default
          via: 10.10.0.1
        - to: default
          via: fe80::1
      nameservers:
        addresses:
          - 1.1.1.1
          - 8.8.8.8
        search:
          - lab.local

Document each field with a comment in your notes:

  • renderer: networkd - which backend applies this.
  • dhcp4: no and dhcp6: no - prevent DHCP from overriding.
  • addresses: - the static IPs with prefix lengths.
  • routes: - default route via IPv4 gateway and IPv6 link-local.
  • nameservers: - DNS resolvers and search domain.

Task 3: Validate the file

sudo netplan generate

netplan generate produces the renderer config from your YAML without applying it. If the YAML has a syntax error, the output shows where.

Task 4: Apply safely

sudo netplan try

You have 120 seconds to verify the change. If you do not press Enter, the change reverts.

In a separate session (or after the change), verify:

ip addr show eth0
ip route show
cat /etc/resolv.conf
networkctl status eth0

Confirm:

  • IPv4 address is 10.10.0.50/24.
  • IPv6 address is 2001:db8:10:10::50/64.
  • Default routes via 10.10.0.1 and fe80::1 are present.
  • /etc/resolv.conf lists 1.1.1.1, 8.8.8.8, and the search domain lab.local.

If all four are correct, confirm with Enter in the netplan try session. If anything is wrong, wait for the timeout.

Task 5: Test end-to-end connectivity

ping 10.10.0.1            # gateway
ping 1.1.1.1              # public IP
ping google.com            # DNS + public IP
dig example.com            # explicit DNS test
curl -I https://example.com

Every command should succeed.

Task 6: Make it permanent

If netplan try confirmed, the configuration is already written. netplan apply will commit it immediately without a revert window:

sudo netplan apply

If you skipped netplan try (because you were confident in the YAML), netplan apply is what you used.

Task 7: Document the rollback

The rollback is to delete the new file and re-run netplan apply:

sudo rm /etc/netplan/99-static.yaml
sudo netplan apply

This restores DHCP from any earlier file (e.g. 00-installer-config.yaml or 50-cloud-init.yaml).

For cloud-init hosts, you may also need to disable cloud-init’s network configuration:

sudo bash -c 'echo "network: {config: disabled}" > /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg'

Validation

  • The host has 10.10.0.50/24 and 2001:db8:10:10::50/64 on eth0.
  • Default routes via both IPv4 and IPv6 gateways exist.
  • /etc/resolv.conf lists the configured DNS servers and search domain.
  • ping to gateway, public IP, and hostname all succeed.
  • dig returns expected results.
  • The rollback procedure has been rehearsed or at least documented.

Cleanup

If you want to revert to DHCP:

sudo rm /etc/netplan/99-static.yaml
sudo netplan apply

What you learned

  • Netplan is the declarative layer on Ubuntu; networkd or NetworkManager applies it.
  • netplan try is the safe way to apply remote network changes.
  • The combination of networkctl status, ip addr, ip route, and an external ping is the verification suite for any network change.
  • Cloud-init can reapply DHCP on every boot if its network configuration is not disabled.

Deliverables

  • · A working /etc/netplan/ file with rationale for each field
  • · Output of networkctl status before and after
  • · Output of ip addr, ip route, and a connectivity test
  • · A documented rollback plan

Verification status

Last reviewed
2026-08-09
Executed end to end
not yet run on hardware

The commands and configuration here have been reviewed against the verified software versions, but nobody has run this lab start to finish on a system meeting its prerequisites. Treat the Expected Outcome as the intended result rather than an observed one, and keep the Cleanup section to hand.