Networking 101: Back to School
Tags: sre, networking, ccna, linux
Published: 2024-05-25 06:34:04

Hola! Hope your networks are stable and reliable. In this article let's get **_Back to School_** (the **Basics**), in order to later get into advanced networking topics.

## What is a network?
A network is interconnection between multiple devices enabling them to share data between each other. An example:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hpsyd0i2i0fsukpglayc.png)

Hmmm... The network doesn't look that impressive. Right?

Maybe this is better.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k9gccfww6of9tljfeb7m.png)

Still not impressed. You must be thinking where the networking devices like a router or a switch or a bridge are, something should be there. But actually, for the above scenarios these networks will just do fine. There is no use of overengineering stuff and bringing-in extra networking devices which serves no actual purpose but can be a single-point of failure.

## Why internetworking? Why not a huge network like this?
Let's now understand why we don't create a huge network of directly/indirectly connected devices, but instead have interconnected smaller networks. And how broadcast and collision domains affect this decision. 

### Collision
Let's understand what a **collision** is. In a network when two devices want to send data, they send signals (electromagnetic along the transmission medium). Now, if two devices try to send data at the same time in the same medium, the signals mix up or **collide** with each other and there is signal loss. When a collision occurs all the devices on the network has to pay attention to it, because nobody knows what the destination on the data signal that was collided. Also, now the data has to be re-transmitted. This **increases computation** for all devices, **increases latency** in the network.

> So, for any device the **smaller** the size of **collision domain** is, **lesser** is the chance of any **collision happening**.

### Broadcasting
Now, let's understand what is **broadcasting**. In broadcasting, a device is trying to send some data across the network, so that multiple devices can receive and acknowledge it. On a bigger network, there may be a few devices in this case who doesn't need this data. But still they have to see it, receive it, acknowledge it, check if it needs this data and lastly just drop the data received. For this device, we want to limit the broadcasting domain only to the devices that it actually needs to talk to, while will reduce the computation getting wasted on dropping un-intended data.

### Another common problem...
**Congestion**, it is the thing we as network admins have to always look after and try to reduce. Congestion is similar to traffic jams on the roads. Whenever, collision occurs the **packets** have to be retransmitted, on unnecessary broadcasts for the unintended devices there are packets travelling on the network, it will have to wait to send its own data. These are the common examples of congestion. Our goal is to somehow reduce this. Now, let's try to find ways of doing. For that we need to introduce few networking devices, so first let's learn about them.

## Understanding the devices
**Domains**. What is a domain? A domain is a region or in this case set of devices.

Types of domains in networking:
- **Collision Domain**
A collision domain for a device is the set of devices who if try to send a signal at the same time as this device, the signals collide. 

- **Broadcast Domain**
A broadcast domain for a device is the set of devices who receives the packet broadcasted by this device.

> Collision domain is always a **subset** of the broadcast domain.

### Hub
A hub is a **dumb** network device with several ports used to connect multiple devices or small networks together. In a Hub, a packet received in any port is re-transmitted to the remaining ports. It doesn't read the packet or anything, it just regenerates the signals received on one port to the remaining that's it.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p54sx6cnr0uehug962y7.png)

The devices A, B, C are all connected to this hub. Now, let's take an example where A wants to transmit to B. It sends a packet out on the network; it reaches the hub, and the hub retransmits on the remaining ports. So, B receives the packet successfully. Cool right? Not actually, because C will also receive the packet now it will have to do the computation that the packet was not intended for it and drop which was not something cool for device C. Here, both the collision domain and broadcast domain for **A** was **{A, B, C} only**.

> Hubs are cheap but always lead to congestion.

### Bridge
A bridge can be called an **intelligent** hub. The term ***"bridging"*** here simply refers to packets bridging over ports. Here, when a packet arrives in one port like hub, instead of being retransmitted to all the ports, the bridge transmits that to the port which it is destined for. I will not be going to show any bridge diagram below as nowadays we don't buy physical bridges. The bridge technology is rather used in switches and routers which we will talk after this.

> Cisco sometimes refers to their switches as multiport bridge, but now you won't get confused why.

> Bridges can be used to reduce collisions in a broadcast domain. It increases the number of collision domains and hence provides higher bandwidth for devices.

### Switch
A switch is an intelligent device which exactly knows which device or network is connected to each port and smartly routes/**bridges**/***switches*** the packets between incoming and destination ports. Here each port creates its own isolated collision domain thus **reducing congestion** in the network. But still as its just switching packets in same network, the broadcast domain remains same.

Let's modify our previous example to make it better.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p63mbljjg2jwxb7mw9qf.png)

Now let's analyze the devices.

**Device B:**
It is directly connected to a port on the switch. So, its collision domain is isolated to the port itself. That is the collision domain for it is **{B}**. That means collision will never occur hence using maximum available bandwidth to the switch. Can it talk to A? Yes, the packet first reaches the switch, the switch checks the destination of the packet and decides to send it to the port in which the hub is connected. The packet then arrives at the hub, and it transmits it to both A and B. Here, A successfully receives the packet, but B also receives it and then drops it.

**Device A, C:**
Both of them are connected to the hub, therefore their collision domain is **{A, C}**. They both can obviously talk with each other and can also talk to B via the reverse of the route we just discussed before.

> In this case, the broadcast domain remains same **{A, B, C}** for all the devices.

### Router
A router is a switch only. The difference is that a switch switches packets in a **single broadcast domain**. But a router is used to switch packets across **multiple broadcast domains**. Explained simply, a router is used to connect **multiple networks** (this also means it can connect several **smaller networks or sub-networks or subnets** within a **bigger network**. This can also be phrased as it can connect **multiple broadcast domains** within a **wider broadcast domain**). How a packet in one subnet would go another subnet, you may ask? Routers do something called NAT (Network Address Translation) to translate the source, destination addresses of the packets from one subnet to another. We will discuss about NAT in a later article.

Let's modify our example before. We had assumed that all the devices are in a same room. Let's modify it in a way A, C remains in one room and B is in another, each room using its own subnet. Also, as we got the chance to modify our network, let's make it better by replacing the hub with a switch.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xny1q01awqx5nv8iwryg.png)

Let's again analyze the devices.

**Device B:**
It is connected to a port on the router and therefore has an isolated collision domain **{B}** **eliminating congestion**. Can it talk to A or C? Yes, the packet the first goes to router the packet is **translated** to the subnet of **Room 1** and then sent to the switch, the switch then switches the packet **only to the intended device**. Here broadcast domain is only **{B}**

**Device A, C:**
Both of them are connected to the switch. A and C, they have their own isolated collision domains **{A}** and **{C}** respectively that they themselves are only present eliminating any collision. Can it talk to B? Yes, again through the reverse of the route discussed before. Broadcast domain for both of them is **{A, C}**.

> Switches create separate collision domains within a single broadcast domain.

> Routers provide a separate broadcast domain for each interface. Don’t let this ever confuse
you!

___

Let's end here for today. In the next article let's discuss network topologies, internetworking models, and a few common protocols.

Please comment below suggesting any changes, asking for any topic, or just hanging out in general. Also, pls reach out to me on my social channels.
[[GitHub]](https://github.com/sith-lord-vader) [[LinkedIn]](https://www.linkedin.com) [[Instagram]](https://www.instagram.com/xpertr2) [[YouTube]](https://www.youtube.com/@xpertdev)