How to Configure Netplan and systemd-networkd on Ubuntu Server for Static IP Routing and VLANs

Modern Ubuntu Server releases (including 20.04 LTS, 22.04 LTS, and 24.04 LTS) utilize Netplan as the default declarative network configuration abstraction. Rather than manually editing legacy /etc/network/interfaces scripts, network engineers define network interfaces, static IP routing tables, 802.1Q virtual LANs (VLANs), and network bonding within structured YAML files parsed by systemd-networkd at boot.

Understanding Netplan YAML Hierarchy and Placement

Netplan parses configuration files alphabetically from /etc/netplan/*.yaml. To identify the active configuration on your system:

ls -l /etc/netplan/
cat /etc/netplan/00-installer-config.yaml
YAML Directive Network Purpose Configuration Rule
renderer: networkd Specifies backend daemon. Use networkd for headless servers; NetworkManager for desktop.
ethernets: Defines physical adapters. Identifies hardware NICs (e.g., eth0, enp3s0).
vlans: Defines 802.1Q virtual subnets. Pairs a unique VLAN ID with a physical parent link.
routes: Static kernel IP routing table. Defines destination CIDR blocks and specific gateway hops.

Configuring Static IPv4 Addressing and Upstream DNS

To assign a static IP address, subnet mask, default gateway, and trusted DNS nameservers to a physical NIC, edit your Netplan configuration file (e.g., /etc/netplan/01-netcfg.yaml):

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: no
      addresses:
        - 192.168.1.50/24
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses:
          - 1.1.1.1
          - 1.0.0.1
        search:
          - corp.internal

Important: YAML is strict regarding indentation. Always use 2 spaces per indentation level; never use tab characters.

Configuring 802.1Q VLAN Tagging

When connecting a server to a trunked switch port carrying multiple isolated broadcast domains (such as management, DMZ, and internal storage traffic), append a vlans mapping stanza:

  vlans:
    vlan50:
      id: 50
      link: enp3s0
      addresses:
        - 10.50.0.25/24
      routes:
        - to: 10.50.0.0/16
          via: 10.50.0.1

Here, the virtual interface vlan50 tags all outgoing frames with VLAN ID 50 and routes traffic across the parent physical link enp3s0.

Testing and Applying Configurations with netplan try

Applying network changes on remote servers over SSH carries the risk of accidental lockouts if a syntax error or incorrect gateway is committed. Always test new configurations using the netplan try safeguard:

sudo netplan try --timeout 30

Netplan applies the new configuration temporarily. If you do not press Enter within 30 seconds to confirm connectivity, Netplan automatically rolls back to the previous known working state, preserving your SSH session.

To permanently apply changes after manual verification:

sudo netplan apply
ip addr show
ip route show

Using Netplan paired with systemd-networkd guarantees clean, reproducible, and resilient network configurations on enterprise Ubuntu servers.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.