Skip to main content
  1. Posts/

Create a Network Bridge on Linux

·715 words·4 mins·
How-to / Guides Linux Networking Bridging
Table of Contents

Introduction
#

A network bridge on Linux allows you to connect two or more network interfaces together at Layer 2 (Ethernet level). This allows your device to act basically like a virtual switch.

Fun fact, this is how hypervisors like Proxmox and Nutanix put their VMs onto a network

What I Wanted to Do
#

In my setup, I had:

  • A Windows PC connected directly to one 10G NIC on my Linux box
  • My NAS connected to another 10G NIC on the same Linux machine

I wanted to bridge the two NICs on my Linux machine so the PC, Linux box and NAS could all talk to each other directly over this 10G link — like a switch


Step-by-Step: Bridging the NICs
#

This guide shows how to do this in the terminal, because I found for me it’s a bit faster and more simple than using the GUI that comes with most DE’s

PreReq – Identify the Interfaces
#

You first need to Identify the interfaces that you wish to bridge. An easy way to do this is typing ip a into your terminal.

This will show you all the interfaces you have attached to your machine. From here you should be able to Identify the interfaces that are unused and you wish to bridge

IP A
For me, its easy to tell because the one that has an IP, is my standard gigabit interface, and I don’t want to bridge that. I have (2) ports on this 10g card, so the ones that are named enp5s0f0 and enp5s0f would be my guys.

1. Clean up existing connections
#

We want to start by cleaning up any old connections that may be tied to these interfaces

sudo nmcli connection delete enp5s0f0
sudo nmcli connection delete enp5s0f1

2. Create the bridge
#

sudo nmcli connection add type bridge ifname nas_bridge con-name nas_bridge

I wanted the name for mine to be ’nas_bridge’ if you wish to change that, just change the command to reflect that


3. Add both NICs to the bridge
#

sudo nmcli connection add type ethernet ifname enp5s0f0 master nas_bridge
sudo nmcli connection add type ethernet ifname enp5s0f1 master nas_bridge

4. Assign a static IP and optional enable jumbo frames
#

If you want the machine you are making the bridge on, to have a presence on the network you need to give it an IP.

Now, in my case there is no DHCP server running on this network, as it is just direct connections, so I need to give a manual static address. If you are running DHCP, you can skip this step as you will already have an IP

sudo nmcli connection modify nas_bridge ipv4.addresses xx.x.xxx.xx/24
sudo nmcli connection modify nas_bridge ipv4.method manual

Replace xx.x.xxx.xx/24 with your IP address of course!

Optional – Set jumbo frames
#

If you are using 10G, and everything supports it, it’s good practice to enable jumbo frames on these connections.

If you set jumbo frames on one device, they must be enabled on every device on this network!

sudo nmcli connection modify nas_bridge 802-3-ethernet.mtu 9014
sudo nmcli connection modify bridge-slave-enp5s0f0 802-3-ethernet.mtu 9014
sudo nmcli connection modify bridge-slave-enp5s0f1 802-3-ethernet.mtu 9014

5. Disable Spanning Tree Protocol (STP)
#

Since this is a simple direct connection and not part of a looped network, STP just adds delay:

sudo nmcli connection modify nas_bridge bridge.stp no

6. Bring it all up
#

sudo nmcli connection up nas_bridge
sudo nmcli connection up bridge-slave-enp5s0f0
sudo nmcli connection up bridge-slave-enp5s0f1

Verifying the Bridge
#

Check the IPs and MTU:

ip a

Make sure nas_bridge, enp5s0f0, and enp5s0f1 all show mtu 9014.

Check that the NICs are enslaved:

bridge link show

You should see something like:

enp5s0f0: master nas_bridge ...
enp5s0f1: master nas_bridge ...

Jumbo Frame Test
#

To test jumbo frame support between the machines:

ping -M do -s 8972 <other-device-ip>

If it succeeds, jumbo frames are working.


Finishing Up
#

Remember, if you are not running a DHCP server on this network, you need to also give the other machines static IP’s in the same subnet.

Once they are all IP’d and up, everything should be talking like planned!


With this setup, my PC and NAS can talk at full 10G speeds, directly through my Linux box acting as a software switch. Pretty neat!

Related

Total Fedora Linux Install Guide--Part 3: Ricing out KDE, a Customization Guide
·1445 words·7 mins
How-to / Guides Fedora KDE Linux
Total Fedora Linux Install Guide--Part 2: Configuring and Setting up Fedora
·1597 words·8 mins
How-to / Guides Fedora KDE Linux
Total Fedora Linux Install Guide--Part 1: Installing Fedora KDE, standalone or with Windows
·1237 words·6 mins
How-to / Guides Fedora KDE Linux