Awab Syed

Mechanical | Controls | Robotics

Network Bridge using nmcli

Posted on: February 20, 2024

This blog provides a step-by-step guide on creating a network bridge using nmcli, the command-line interface for NetworkManager. A network bridge allows multiple interfaces (like Ethernet and virtual machines) to share the same physical network, often used in virtualization setups.

What is a Network Bridge?

A bridge behaves like a virtual network switch. Instead of assigning an IP to each interface separately, you attach them to the bridge. This is commonly needed when running virtual machines (e.g., with KVM/QEMU) so they can appear directly on the network like any other device.

Steps to Create a Bridge with nmcli

  1. Create the bridge interface
    nmcli connection add type bridge ifname br0 con-name br0
    Here, br0 is the name of the new bridge.
  2. Assign an IP configuration to the bridge You can set it to DHCP or a static IP. Example with DHCP:
    nmcli connection modify br0 ipv4.method auto
    Or for static IP:
    nmcli connection modify br0 ipv4.addresses 192.168.1.100/24
    nmcli connection modify br0 ipv4.gateway 192.168.1.1
    nmcli connection modify br0 ipv4.dns 8.8.8.8
    nmcli connection modify br0 ipv4.method manual
  3. Add a physical interface (e.g., eth0) to the bridge
    nmcli connection add type ethernet ifname eth0 master br0
    This enslaves eth0 to the bridge.
  4. Bring up the bridge
    nmcli connection up br0
    Verify with:
    ip addr show br0

Verification

After setup, the bridge interface (br0) should have the assigned IP, while the physical interface (e.g., eth0) won’t carry an IP anymore but will pass traffic through the bridge.

Conclusion

Using nmcli to create a network bridge is a reliable way to integrate physical interfaces and virtual machines into the same network. This is particularly useful for development, testing environments, or when setting up KVM/QEMU virtualization. Future posts will cover how to connect virtual machines to this bridge in practice.

← Back to Blog