Learning Networking Basics - 2

Tawaliou ALAOTawaliou ALAO
4 min read

Continuing my learning on networking basics, I learned about the Ethernet Switch, which is part of the physical layer of the OSI Model and the Network Access Layer of TCP/IP. I also discovered some interesting details about how the Ethernet switch forwards packets.

Ethernet switch

Ethernet Frame

The Ethernet switch, or simply switch, lets devices connect within a LAN. Its job is to forward or transmit packets (also known as Ethernet Frames) from a source device to a destination device using the MAC address of the Network Interface Card (NIC) in each device. A packet is just a sequence of bits (0s and 1s).

In the image below, you can see an example of a packet.

Picture 1- Ethernet Frame Yapısı – Huseyin Pala

So, we might ask, in a LAN, how does the switch know the device's MAC address to determine where to forward a packet? Let's look at this picture of a simple LAN.

My initial thought was that when a device connects to the LAN, it sends its NIC's MAC address to the switch, like a registration. This way, the switch would have the MAC addresses of all devices connected to the LAN, and when it receives a packet, it could use the destination MAC address in the packet to send it to the correct device.

But that's not exactly how it works: In reality, the NIC in devices doesn't know if it's connected to a switch, so it doesn't need to send its MAC address. Also, the protocol must be designed to work independently of specific devices like the switch..

MAC Address Table

The switch has a MAC address table where it stores device MAC addresses along with the port each device is connected to.

When a packet is sent:

  1. The switch first checks if the Source Address is already in its MAC address table.

  2. If it is, and the Destination Address is in the table, it forwards the packet to the port where the destination device is connected. If the Destination Address is not in the table, it broadcasts the packet to all ports except the source port.

  3. If the Source Address is not in the table, the switch adds it with the corresponding port, then proceeds as in step 2, either broadcasting or directly forwarding the packet.

  4. When a device connected to the switch receives the packet, it processes the packet if the Destination Address matches its MAC address; otherwise, it discards the packet.

Here is a short illustration of this process: that.

Ethern frame foward politic by switch

As we can see, it's a "simple" method to send packets and save MAC addresses simultaneously, using fewer resources. The table updates each time a new packet is sent.

Let me share another thing I learned about IPv4..

IPv4 (Network + Host)

In IPv4, there are Network and Host parts. The network part, also known as the Subnet, indicates which network the device is part of, while the host part identifies the specific device. Refer to the following image.

IPv4: Network + Host

Here are a few things to understand:

  • When we have an IPv4 address 192.168.5.123/24, the 24 indicates that the first 24 bits (192.168.5.0) represent the network address.

  • The subnet mask, 255.255.255.0, serves the same purpose as the 24: it identifies the network. So, if we have these two pieces of information: 192.168.5.123 and 255.255.255.0, it means that 192.168.5.0 is the network address.

To conclude, there can be a broadcast address like 192.168.5.255, which acts as a sub-group for devices with the same address. If a packet is sent to this address 192.168.5.255, all devices with this broadcast address will receive the packet.

Now, on Linux, when we run ifconfig -a and see a display like the following, we understand what the second line means.

Conclusion

There are many things I read, use, and see, but I don’t really understand their meanings. It's good to have a little bit of knowledge about them, like the whole world of networking.

0
Subscribe to my newsletter

Read articles from Tawaliou ALAO directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Tawaliou ALAO
Tawaliou ALAO

Software Developer | Love Low Level Eng. | Python, Javascript, C, Linux I'm learning backend development and system programming.