In Debian Linux, you can configure network interfaces as a bridge, also known as a network switch, using the brctl
utility and the /etc/network/interfaces
file.
Here’s an example of how to configure two network interfaces, eth0
and eth1
, as a bridge:
- Install the
bridge-utils
package:sudo apt-get install bridge-utils
- Create a bridge device:
sudo brctl addbr br0
- Add the network interfaces to the bridge:
sudo brctl addif br0 eth0 eth1
- Configure the network interfaces in the
/etc/network/interfaces
file:
# /etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet manual
# The secondary network interface
auto eth1
iface eth1 inet manual
# The bridge network interface
auto br0
iface br0 inet dhcp
bridge_ports eth0 eth1
- Restart the networking service:
sudo systemctl restart networking
Note: You will need to replace the dhcp
with a static IP configuration if necessary.
This configuration creates a bridge device named br0
and adds the eth0
and eth1
interfaces to it. The bridge device is assigned a DHCP IP address. Any packets received by the bridge device will be forwarded to the appropriate interface based on the destination MAC address.