Mets Minor League Blog

Music theory, instruments and musicians

Mets Minor League Blog

Music theory, instruments and musicians

How to Add a Network Bridge br0 on Ubuntu 20.04 with nmcli

How to Add a Network Bridge br0 on Ubuntu 20.04 with nmcli

Creating a network bridge like br0 on Ubuntu 20.04 allows you to connect multiple network interfaces, virtual machines, or containers to the same network segment seamlessly. This setup is essential for virtualization, network isolation, or when you want a device to act as a network hub. Using nmcli, the command-line tool for NetworkManager, provides a flexible and scriptable way to configure network bridges without editing configuration files directly. Before starting, ensure your system has NetworkManager installed and active, and that you have administrative privileges (sudo access).

What You’ll Need

  • Ubuntu 20.04 system with administrative (sudo) privileges
  • NetworkManager installed and running (default on Ubuntu 20.04)
  • Basic familiarity with command-line interface
  • Optional: existing network interfaces if you plan to add them to the bridge

Step-by-Step

  1. Open a terminal window: Access your system’s terminal to run commands.
  2. Check current network interfaces: List existing interfaces to identify the ones to bridge.
    nmcli device status

    This command shows all network devices and their statuses.

  3. Create the bridge connection named br0: Run the following command:
    sudo nmcli connection add type bridge con-name br0 ifname br0

    This creates a new bridge connection called br0.

  4. Add an interface to the bridge (optional): If you want to add an existing interface (e.g., eth0) to the bridge, run:
    sudo nmcli connection add type ethernet con-name bridge-port ifname eth0 master br0

    Replace ‘eth0’ with your actual interface name. If you want the interface to be managed by NetworkManager, ensure it is not set to ‘unmanaged’.

  5. Set the bridge interface to be active: Bring up the bridge with:
    sudo nmcli connection up br0

    This activates the bridge connection.

  6. Configure IP settings for the bridge: Assign IP addresses as needed. For static IP, run:
    sudo nmcli connection modify br0 ipv4.addresses 192.168.1.100/24 ipv4.method manual

    For DHCP, use:

    sudo nmcli connection modify br0 ipv4.method auto

    Then, bring the connection down and up again to apply:

    sudo nmcli connection down br0 && sudo nmcli connection up br0
  7. Verify the bridge configuration: Confirm that the bridge is active and interfaces are correctly associated:
    nmcli connection show --active

    Look for br0 and ensure its state is ‘activated’.

  8. Test network connectivity: Check that your system is reachable via the new bridge setup, and test connectivity to other devices or the internet.

Common Mistakes

  • Not specifying the correct interface names: Always double-check interface names with nmcli device status.
  • Forgetting to activate the new connection: Remember to run nmcli connection up br0.
  • Incorrect IP configuration: Ensure IP settings are correctly applied, especially if switching between DHCP and static IPs.
  • Not removing conflicting network configurations: Disable or delete any pre-existing network connections that might interfere.
  • Not rebooting or restarting NetworkManager after changes: Sometimes, a restart helps apply complex configurations.

Tips

  • Always backup your current network settings before making major changes.
  • Use nmcli connection show to list all configurations and verify your new bridge setup.
  • For complex setups, consider scripting nmcli commands for repeatability.
  • If you encounter issues, restart NetworkManager with sudo systemctl restart NetworkManager.
  • Use the GUI NetworkManager tool (if available) for visual confirmation and easier management.

Troubleshooting

If your bridge does not work as expected, take these steps:

  • Check the status of the bridge: Run nmcli device status and nmcli connection show --active to verify the bridge is active.
  • Inspect logs for errors: Use journalctl -u NetworkManager to identify possible errors or conflicts.
  • Ensure interfaces are not unmanaged: Sometimes, interfaces are set to unmanaged mode, preventing bridge configuration. Check with:
    nmcli device show

    and adjust if necessary.

  • Remove conflicting connections: Delete or disable old network configurations that might conflict with your bridge setup:
    sudo nmcli connection delete 
  • Reboot or restart NetworkManager: Restart the network service to apply changes cleanly:
    sudo systemctl restart NetworkManager

If problems persist, consider manually editing /etc/netplan or /etc/network/interfaces, but this is generally unnecessary with nmcli on Ubuntu 20.04.

Frequently Asked Questions

1. Can I add multiple interfaces to the br0 bridge?

Yes, you can add multiple interfaces to the bridge by creating additional connection profiles with master br0 for each interface.

2. Will creating a bridge disrupt my current network connection?

It might temporarily disrupt your connection during configuration. It’s best to perform this with physical access or in a controlled environment.

3. How do I delete the bridge if I no longer need it?

Use sudo nmcli connection delete br0 to remove the bridge configuration safely.

4. Can I use this setup with Wi-Fi interfaces?

Bridges with Wi-Fi interfaces are more complex and often require specific configurations. Typically, bridging Wi-Fi interfaces is not straightforward and may need additional tools like hostapd or bridging modes.

5. How do I make the bridge persist across reboots?

NetworkManager automatically saves configurations. Ensure the connection is set to autoconnect, which is the default. You can verify with nmcli connection show.

6. Is it possible to create a bridge with DHCP?

Yes, set the ipv4.method to auto when configuring the bridge, and NetworkManager will handle DHCP assignment.

Creating a network bridge on Ubuntu 20.04 using nmcli provides a powerful way to manage complex network setups efficiently. Follow these steps carefully, avoid common pitfalls, and use troubleshooting tips to ensure a successful configuration that suits your networking needs.

Related

How to Add a Network Bridge br0 on Ubuntu 20.04 with nmcli
Scroll to top