Skip to content

Instantly share code, notes, and snippets.

@arifbalik
Created August 30, 2023 13:07
Show Gist options
  • Save arifbalik/2a937de0381e9218329395994a94393f to your computer and use it in GitHub Desktop.
Save arifbalik/2a937de0381e9218329395994a94393f to your computer and use it in GitHub Desktop.
Setting Up a Bridge Between Two Ethernet Interfaces (Layer 2)

Setting Up a Bridge Between Two Ethernet Interfaces

To create a network bridge between two Ethernet interfaces (eth0 and lan0) on a Linux system, you can use the following steps:

  1. Open a terminal window.

  2. Edit the /etc/network/interfaces file using a text editor with administrative privileges. For example, you can use sudo and nano:

    sudo nano /etc/network/interfaces
  3. Add the following configuration lines to the end of the file:

    auto br0
    iface br0 inet static
        address 192.168.1.200
        netmask 255.255.255.0
        gateway 192.168.1.1
        bridge_ports eth0 lan0
        bridge_stp off
        bridge_fd 0
        bridge_maxwait 0
        up /etc/init.d/ssh restart
    
    • auto br0: This line ensures that the bridge interface (br0) is brought up automatically during system boot.
    • iface br0 inet static: This indicates that the bridge interface will have a static IP configuration.
    • address 192.168.1.200: Assigns the IP address 192.168.1.200 to the bridge interface.
    • netmask 255.255.255.0: Sets the subnet mask to 255.255.255.0.
    • gateway 192.168.1.1: Specifies the default gateway IP address.
    • bridge_ports eth0 lan0: Indicates that the bridge interface will bridge traffic from the eth0 and lan0 interfaces.
    • bridge_stp off: Disables the Spanning Tree Protocol to prevent network loops.
    • bridge_fd 0: Sets the bridge forwarding delay to 0 seconds for immediate forwarding.
    • bridge_maxwait 0: Sets the maximum wait time for the bridge to become operational to 0 seconds.
    • up /etc/init.d/ssh restart: Restarts the SSH service when the bridge interface is brought up.
  4. Save the changes and exit the text editor.

  5. Restart the networking service to apply the changes:

    sudo service networking restart

    Note: The exact command to restart the networking service might vary based on your Linux distribution.

  6. Your bridge configuration should now be active. You can verify its status using tools like ip or ifconfig.

That's it! You have successfully set up a network bridge between the eth0 and lan0 Ethernet interfaces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment