Bridge networks
can be created using a multitude of methods, This second method
will be using systemd. In this case, we're using base Debian 12,
and we are logged in as root, and it's worth noting that to make
a bridge network utilizing a wifi device, other steps are
required which won't be expounded on in this article. We are
using ethernet devices for this guide, and most likely you will
too. Other distributions than Debian utilize systemd, so even if
you're not using Debian, this method is likely applicable. Start
by listing the network interfaces:
"ip a"
Here we see a local loopback (lo) and we see ens3, ens3 being
the main interface. Though it may be a different name in your
case, for example eth0, ens2, enp1s0, enp9s0, etc. Take note of
this interface name. In some cases where you are bridging
multiple interfaces, for example you have 2 or 3 ethernet ports
you're wanting to bridge, there may be more interface names
here, and if so take note of these names if you want to bridge
these interfaces. Also take note of the ipv4 address assigned to
this interface, in this case 192.168.1.180/24, as to not use the
same IP for a static bridge IP later on. Assuming there are no
modifications to the host's interfaces or routing tables, and
the interfaces were automatically set up by the host system,
continue reading.
Now, in order to keep our method using systemd-networkd
functional between reboots, we will have to make sure no other
network daemons are enabled on startup, because they may
conflict with our configuration. This means if
NetworkManager.service or connman.service, networking.service,
or any others are enabled, they should be disabled! These names
of network daemons are examples and depending on your system,
you may have one or several, going by different names.
We'll check this now by using "systemctl status
networking.service" or "systemctl status connman.service" or the
name of an equivalent daemon. Then running "systmctl disable
networking.service" The only network daemon we want running is
systemd-networkd, to check this use "systemctl status
systemd-networkd.service" This output shows systemd-networkd is
installed and is disabled. If this service is disabled, enable
it now. "systemctl enable systemd-networkd.service"
Now that all the network daemons are disabled except
systemd-networkd, and our interfaces file is backed up and
renamed, we can move right into creating our configuration files
for our bridge. Begin by changing directory into
/etc/systemd/network/
"cd /etc/systemd/network/"
Using the editor of your choice, nano in this case, create a
new file with the extension ".netdev" in this directory.
I will be naming this "bridge.netdev"
"nano bridge.netdev"
Here we will create the device known as "br0" and specify its
type as a bridge.
Save and close the file and create another file in the same
directory with the name "1-br0-bind.network" this time with the
extension ".network". Because the systemd-networkd daemon will
run these files at boot in order based on their name, we will
prefix this file with the number 1.
In this configuration file, we set up the bridge device, br0,
to bind or use ens3 as its master or main interface. Save and
close this file. At this point, we have set up a new bridge
device, and bound it to our primary ethernet interface.
Depending on whether you would like a static IP assigned to the
bridge interface, or let it be assigned by DHCP, there are two
options from here.If you want to use DHCP, create a file called
"2-br0-dhcp.network"
"nano 2-br0-dhcp.network"
Save and close the file.
You can see I specified a DNS and Gateway address, this is not
necessary in all cases, but in my case I did specify.
You could add multiple lines for multiple DNS and Gateway
addresses.
If you want to use a static IP address for the host bridge,
create a file called "2-br0-static.network" and add the
"Address" line set to whichever available ip you desire.
That's it! After creating these three files, reboot your system
and use "ip a" to show your network interfaces. Whether you used
the DHCP setup or the static IP setup, you'll see something like
this shown below, displaying a new interface named br0, with its
master being ens3. Here we see the address assigned to this br0
interface automatically set to 192.168.1.247/24. To check for
internet connection, you can use ping with a count of 5 to any
external ip address.
"ping -c 5 1.1.1.1"
For more detailed information about how to write
systemd-networkd configuration files, refer to the Manual
for systemd-networkd, or
Octetz.com
Special thanks to Josh Rosso from Octetz.com
for his superb guide to creating bridge networks in systemd!