Comment on What is a router ?

Nibodhika@lemmy.world ⁨2⁩ ⁨hours⁩ ago

Let’s get into very basic things.

You have two computers you want to connect, you grab a cable, plug it in both and voila!

You now need to connect a third computer, you could have a three way cable, but that makes it hard to replace things. Instead you have a box that has multiple connectors and internally it just connects all of them, essentially making a multi-end cable ok demand, this is what’s called a Hub because it’s just a centralized location where every package goes in/out.

But now your machines need to know how to send messages to one or another, so you implement a protocol where each machine has a number, and every message sent you encapsulate in a header saying something like “For X”, and computers know their own number so they can discard messages that are not for them.

Cool, but as you add more computers and longer cables the signal might become weak, you could add a very small chip to that box and some electricity so it can now act as a repeater. Most hubs were also repeaters, it was a small extra cost but a lot of extra functionality so it was an easy choice.

As you add more computers you start to have an issue, whenever two computers send a message at the same time they collide and no one receives it. Now, this is silly, you have computer 1 sending a message to computer 2 and computer 3 sending a message to computer 4, there’s no reason these should collide, but because of the Hub they do (because both messages are actually sent to all computers and they just discard what’s not for them).

It’s time to make your box a bit smarter. Instead of naively sending all messages everywhere, you add a computer there, it can understand the protocol we described before, and instead of just being a blind signal repeater. This box now knows which port each computer is plugged in, and so when 1 sends a message to 2 the signal only goes from the port 1 to the port 2, all other ports are free and can send messages at the same time. This is what’s called a Switch, because it switches what output the message goes to.

Cool, but now we have two separate networks, which means there are two Computer 1. You can’t just put one cable between the two switches because they won’t know where computer 1 is. Each switch needs to have it’s own number, and you need to wrap the message twice, e.g. Computer 1 connected to switch 1 wants to send a message to computer 2 connected to switch 2. Switch 2 is connected on port 5 to switch 1, so you wrap your message with something like “For 5, For 2”. The first switch sends to 5, the second switch receives it, notices it’s for himself, discards the first wrapper, and sends to 2.

Magic, right? Well, not quite, you need to know where computer 2 is located, and know all of the path to it. That’s not feasible for users to manage. What if we gave each computer a unique number across networks? It would be a sort of an Inter-Network Protocol address, or an Internet Protocol address for short, or even shorter IP. So now each computer has a unique number, and computer one can just send a message to computer 10 and not have to worry where it is.

But how does the message actually get to computer 10? Well, it’s time to add some extra logic to our Switch, and have it store a table of routes, so it knows that computer 10 is on port 5. Because they now not only know what’s on their ports but what route a package needs to take to reach its destination between networks this device is called a Router.

And there you go. A short introduction to network to explain what a router is and how it works. Obviously I simplified a lot of stuff and the real thing is a lot more complex, but this should give you a good ELI5 version of routers and networking.

source
Sort:hotnewtop