The following network definition cost me some time. I read in an article that the package “bridge-utils” is deprecated and is not required anymore to create network bridges under Debian and it’s derivatives.
Let’s start with the code because that’s what I would be interested in, if I was looking for a solution.
Code
Just replace the addresses marked with “<…>”, store the file in “/etc/network/interfaces” and you’re good to go.
source /etc/network/interfaces.d/*
auto lo br0 eth0
iface lo inet loopback
up ip link add br0 type bridge || true
up ip link add br1 type bridge || true
iface br0 inet static
address <static ipv4 address>
netmask 255.255.255.0
gateway <ipv4 gateway address>
up ip link set br0 type bridge stp_state 1
up ip link set br0 type bridge forward_delay 200
iface br0 inet6 static
address <static ipv6 address>
netmask 64
gateway <ipv6 gateway address>
iface eth0 inet manual
pre-up ip link set eth0 master br0
post-down ip link set eth0 nomaster
iface eth0 inet6 manual
Explanation
Initialization of the loopback adapter is “misused” to initialize the bridge because the looback adapter is started first.
Before “eth0” is started it is attached to the bridge.
The bridge is configured when it is up. This is done in the lines “up ip link set …”
Thus I have to say that I am not 100% sure if this configuration is correct. For example most tutorials say to configure “forward_delay” with a value of “2”. But this does not work and the command always tells me, that the value 2 is out of range. “200” was the lowest I could go without getting an error.
Conclusion
Bridges are a great way to virtualize network traffic on a virtual machine. I have used it to set up three servers with multiple virtual machines and organize the traffic using a pfSense instance also running in a virtual machine. Basically something like:
The firewall then NATs the required ports to the corresponding machines.