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
- Create the bridge interface
Here,nmcli connection add type bridge ifname br0 con-name br0br0is the name of the new bridge. - Assign an IP configuration to the bridge
You can set it to DHCP or a static IP. Example with DHCP:
Or for static IP:nmcli connection modify br0 ipv4.method autonmcli 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 - Add a physical interface (e.g., eth0) to the bridge
This enslavesnmcli connection add type ethernet ifname eth0 master br0eth0to the bridge. - Bring up the bridge
Verify with:nmcli connection up br0ip 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.