How to Use netplan to Configure Static IP Addresses and Bridge Networking on Ubuntu Server

Modern Ubuntu distributions—including Ubuntu 22.04 LTS and Ubuntu 24.04 LTS—utilize Netplan as the default network configuration utility. Netplan serves as a centralized abstraction layer that interprets human-readable YAML configuration files and generates backend configuration state for either systemd-networkd (standard on headless servers) or NetworkManager (common on desktop workstations). Configuring reliable static IPv4/IPv6 addresses, custom DNS resolvers, and virtual network bridges via Netplan is an essential prerequisite for deploying production cloud nodes, hypervisors, and container hosts.

Understanding Netplan Configuration Directory and YAML Syntax

Netplan stores its configuration files under /etc/netplan/. Files are parsed in lexicographical order (e.g., 01-netcfg.yaml or 50-cloud-init.yaml), with subsequent files overriding previous definitions. Because Netplan configurations are strictly formatted in YAML, adhering to exact indentation rules (using two spaces per indent level, never tabs) is mandatory to prevent parse errors.

Step-by-Step: Assigning a Static IP Address on Ubuntu Server

1. Identify Your Active Network Interface

Before editing configuration files, determine the physical or virtual network interface name (such as eth0 or enp3s0):

ip link show

2. Edit the Primary Netplan YAML File

Open or create your network configuration file using your preferred text editor with administrative privileges:

sudo nano /etc/netplan/01-netcfg.yaml

3. Apply the Static IP Configuration

Insert the following configuration template, replacing interface names, IP ranges, gateways, and nameserver addresses with your network’s specific parameters:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: false
      dhcp6: false
      addresses:
        - 192.168.1.150/24
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses:
          - 1.1.1.1
          - 8.8.8.8
        search:
          - lan.local

Configuring Virtual Bridge Networking (br0) for KVM / LXD

Virtualization hosts running KVM, QEMU, or LXD containers require network bridging so that guest virtual machines can obtain their own dedicated IP addresses on the physical local area network. Here is how to bind a physical interface into a virtual bridge:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: false
      dhcp6: false
  bridges:
    br0:
      interfaces: [enp3s0]
      addresses: [192.168.1.150/24]
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses: [1.1.1.1, 8.8.8.8]
      parameters:
        stp: false
        forward-delay: 0

Testing and Applying Netplan Configurations Safely

Applying untested network configurations on remote SSH servers can easily cause permanent disconnects if syntax errors or conflicting gateways are introduced. Netplan provides a dedicated auto-rollback testing mechanism:

1. Test with Auto-Rollback Safety

sudo netplan try

The netplan try command applies the candidate configuration and initiates a 120-second countdown. If you do not press Enter to confirm within the window (for example, if you lost SSH connectivity), Netplan automatically reverts to the previous working configuration.

2. Permanently Apply Changes

Once verified, permanently write and activate the configuration across systemd daemons:

sudo netplan apply

3. Verify the Active Network State

Confirm that the IP address, default route, and DNS resolvers have correctly bound:

ip addr show enp3s0
ip route show
resolvectl status

Get the best tech tips delivered straight to your inbox.

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