keepcalculator

06 Numbers and Powers

Netplan Bridge Network Interfaces: Setup Guide

Card No. 06·86480 · Updated · Standard formula, shown below

Netplan bridges two or more network interfaces into a single logical switch, letting a host share its connection or isolate traffic. You configure it in YAML files under /etc/netplan, then apply it with netplan apply. This guide shows you how to create a bridge, assign an IP, and troubleshoot common issues.

Why Bridge at All?

Bridging is common in virtualization (KVM, LXC), container networking, and when you need to share a single internet connection among multiple devices. A bridge lets guest VMs appear as normal hosts on the LAN, receiving their own IPs from the router, rather than being hidden behind NAT. It is also used to combine two NICs for redundancy (bonding is different, but often paired).

Without a bridge, each physical NIC is independent; traffic cannot pass between them at layer 2. A bridge merges them into one logical segment, so a frame arriving on eth0 can be forwarded out eth1 based on MAC addresses. This is how a software switch works.

How Netplan Bridges Work

Netplan is a YAML-based front-end that generates configuration for either systemd-networkd or NetworkManager. When you define a bridge, Netplan:

  1. Creates the bridge interface (e.g., br0).
  2. Adds the listed physical interfaces as bridge ports.
  3. Applies IP configuration to the bridge, not to the ports.
  4. Disables DHCP and other IP settings on the member interfaces, because they are now layer-2 only.

The generated backend config lives in /run/systemd/network/ (for networkd) or is pushed to NetworkManager. You can inspect it with netplan get (Ubuntu 22.04+) or cat /run/systemd/network/10-netplan-br0.network.

Choosing Between Bridge, Bond, and VLAN

These three are often confused. A bridge merges interfaces at layer 2; a bond combines them for bandwidth or failover; a VLAN splits a single interface into multiple logical networks. You can combine them: e.g., a bond that feeds a bridge, or a bridge with VLAN sub-interfaces.

  • Bridge – use when you need a software switch, e.g., for VMs.
  • Bond – use for redundancy or increased throughput (mode 802.3ad, active-backup).
  • VLAN – use to separate traffic without adding hardware.

If you need both, define the bond first, then the bridge over the bond. Netplan supports nested definitions: bridges: br0: interfaces: [bond0].

Common Problems and Fixes

Bridging often fails due to a few recurring mistakes:

  • No IP on the bridge – if you assign the IP to eth0 instead of br0, the host loses connectivity after applying. Always put addresses under the bridge.
  • DHCP on members – leaving dhcp4: yes on eth0 while it is a bridge port causes conflicts. Netplan usually disables it, but be explicit.
  • Firewall interference – some firewall rules (iptables, nftables) filter bridged traffic. On Ubuntu, the bridge-nf-call-iptables sysctl can block forwarding. Check sysctl net.bridge.bridge-nf-call-iptables and set it to 0 if needed.
  • NetworkManager override – if the renderer is NetworkManager, it may manage the physical NICs and ignore Netplan. Ensure the renderer is consistent.
  • Typos in YAML – indentation errors are common. Run sudo netplan try before apply; it rolls back on timeout if you lose connectivity.

If a bridge port does not come up, check ip link for the physical interface state. Sometimes the NIC is down; set dhcp4: no and optional: true to avoid waiting for carrier.

Bridging with Wi-Fi

Bridging a wireless interface (wlan0) is trickier. Most Wi-Fi drivers do not support layer-2 bridging because they do not allow promiscuous mode on the client side. A common workaround is to use a routed setup (NAT) instead. If you must bridge, use a USB Ethernet adapter or a dedicated access point. Netplan will happily create a bridge with wlan0, but it often fails silently. Test with ping from a device on the bridge.

Safety and Best Practices

Bridging exposes your host to the LAN at layer 2. Any device on the bridge can send arbitrary frames, so do not bridge interfaces that face untrusted networks unless you have a firewall. Also, avoid bridging a NIC that is your only management interface – you may lock yourself out. Always use netplan try instead of netplan apply when testing remotely; it reverts after 120 seconds if you do not confirm.

For production, document the exact YAML and keep a backup. If you need to roll back, sudo netplan revert (on newer versions) or restore the original file.

Frequently Asked Questions

Do I need to assign an IP to the physical interfaces when bridged?

No. The physical interfaces become pure layer-2 ports. All IP configuration (static or DHCP) goes on the bridge interface. Assigning an IP to a member can cause routing conflicts and is not supported by Netplan.

How do I make the bridge get an IP via DHCP?

Set dhcp4: true under the bridge, and set dhcp4: no on the members. Example: bridges: br0: interfaces: [eth0] dhcp4: true. After netplan apply, the bridge will request an address from the router.

Can I bridge a bond and a VLAN?

Yes. Define the bond (e.g., bond0) with its members, then define the bridge over bond0. For VLANs, create a VLAN interface on the bond or physical NIC, then add that VLAN interface to the bridge. Netplan supports nested definitions.

Why does my bridge lose connectivity after a reboot?

Likely the physical NIC is not up when Netplan runs. Add optional: true to the ethernet interface so the system does not wait for it. Also ensure the bridge is in the correct YAML file and that netplan apply runs on boot (it does by default).

What is the difference between a bridge and a switch?

Functionally, a software bridge is a virtual switch. The kernel learns MAC addresses and forwards frames between ports. A hardware switch does the same but in dedicated silicon. For most home labs, a bridge is sufficient.

Can I use NetworkManager as the renderer?

Yes, set renderer: NetworkManager in the YAML. This is common on Ubuntu Desktop. However, NetworkManager may try to manage the physical interfaces; add networkmanager: passthrough: true or set the members to optional: true to avoid conflicts.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →