Computer Network Tutorial: Bridge 🎯

beginner
23 min

Computer Network Tutorial: Bridge 🎯

Welcome to our deep dive into understanding Bridges! In this tutorial, we'll explore what Bridges are, why we need them, and how they function in computer networks. Let's get started!

Understanding Bridges 📝

A Bridge is a device that connects two networks, enabling them to exchange data. By doing so, it divides a large network into smaller, more manageable networks called LANs (Local Area Networks).

Why use Bridges?

  • Network Segmentation: Bridges allow administrators to divide a large network into smaller ones, making network management more manageable and efficient.
  • Improved Performance: By dividing a network, Bridges reduce the amount of broadcast traffic, improving overall network performance.

Types of Bridges 📝

Transparent Bridges

Transparent Bridges function at the Data Link Layer (Layer 2) of the OSI model. They don't modify the MAC addresses of the frames they forward, making them virtually invisible to devices on the network.

Switched Bridges

Switched Bridges, also known as Layer 3 Bridges, can operate at both the Data Link and Network layers (Layers 2 and 3) of the OSI model. They can route based on IP addresses, making them more flexible than Transparent Bridges.

Bridge Operation 📝

Bridges learn the MAC addresses of devices on each network segment and store them in a table called the MAC address table or forwarding database. This table helps the Bridge to make informed decisions about which network to send a frame to.

Bridge Forwarding Process 💡

  1. A device on one network sends a frame to another device on a different network.
  2. The Bridge receives the frame and checks its MAC address table to determine which segment the destination device is connected to.
  3. If the Bridge finds the destination device's MAC address in its table, it forwards the frame to the appropriate segment.
  4. If the Bridge doesn't find the destination device's MAC address, it floods the frame to all segments except the one it received the frame from, waiting for the destination device to respond.

Code Example: Transparent Bridge 💡

Here's a simple example of a Transparent Bridge in Python. This code receives frames from one network segment, checks their destination MAC addresses, and forwards them to the appropriate segment.

python
# Transparent Bridge example in Python import scapy.all as scapy def receive_packets(packet): src_ip = packet[IP].src dst_ip = packet[IP].dst src_mac = packet[Ether].src dst_mac = packet[Ether].dst if dst_ip == "192.168.1.2": # Forward the packet to Segment 2 packet[Ether].dst = "00:00:00:00:00:02" scapy.send(packet) elif dst_ip == "192.168.2.2": # Forward the packet to Segment 1 packet[Ether].dst = "00:00:00:00:00:01" scapy.send(packet) # Comment out the following line for continuous packet forwarding scapy.send(packet) # Create two network segments network_1 = scapy.ARP(pdst="192.168.1.2") / scapy.Ether(dst="ff:ff:ff:ff:ff:ff") network_2 = scapy.ARP(pdst="192.168.2.2") / scapy.Ether(dst="ff:ff:ff:ff:ff:ff") # Create a Transparent Bridge bridge = scapy.SR(network_1 + network_2) # Start sniffing packets and forwarding them scapy.sniff(prn=receive_packets)

Quiz 💡

Quick Quiz
Question 1 of 1

What is the main purpose of a Bridge in a computer network?

In the next part of our Computer Network Tutorial series, we'll explore Routers and their role in computer networks. Stay tuned! 🎯