laitimes

Fun about switches and routers

author:A sprouted potato

How do I quickly confirm the interconnection method of the device?

Little A is an Age of Empires god who has beaten all the levels of the game and can take on 8 crazy computers alone. Gradually, he got bored and wanted to find a partner to PK with.

But how do you connect two devices? A is clever enough to invent a port that can transfer data like a USB port, which he named the network port. A connects his computer to B's network port through a network cable, realizing the interconnection between the two computers.

Fun about switches and routers

The two friends were very happy and played online, when they were seen by little C who was passing by, and little C was about to join in. But we know that each computer has only one network port, and it is impossible to realize the interconnection of three computers, so what should we do?

Fun about switches and routers

At this time, Xiao B came up with an idea: let's find another computer, design a few more network ports for him, and each of us will connect to the network port of this computer, won't it also realize the interconnection between our brothers?

Hub

Fun about switches and routers

So they designed a microcomputer, which has multiple network ports to realize the interconnection of multiple computers, and this microcomputer is the hub. As the name suggests, the hub plays a role in bringing together network cables to achieve the most basic network interoperability. The hub transmits data directly over a network cable, and we say that it works at the physical layer.

Fun about switches and routers

After having the hub, more and more friends joined the game, and little D, little E and others came to visit. However, the hub has a problem, because it is connected to each device, it cannot tell who the specific information is sent to, and can only broadcast it widely. For example, Xiao A originally wanted to ask Xiao C: Have you eaten? As a result, all users connected to the hub, such as Xiao B, Xiao D, and Xiao E, received this information, and because they are on the same network, Xiao A cannot speak when he speaks, otherwise the information will collide and cause an error, which we call each device in the same conflict domain.

Fun about switches and routers
Fun about switches and routers

交换机(NetWork Switch)

Fun about switches and routers

The user experience of such a device is extremely poor, so the friends discuss improvement measures together. That's when the clever little D spoke: let's add a command to this device, so that he can automatically address and transmit data based on the network port name. For example, if I name the network port of Little A as macA and the network port of Little C as macC, if Little A wants to send data to Little C, the device will automatically transfer the data from A's computer to C's computer according to the network port names macA and macC, and will not let Little B, Little D, and Little E receive it. In other words, this device solves the problem of conflicts, realizes the interconnection between any two computers, and greatly improves the transmission speed between networks, which we call a switch. Since the switch transmits information according to the network port address, which is one more step than the direct transmission of the network cable, we also say that the switch works at the data link layer.

Fun about switches and routers
Fun about switches and routers

This time the friends were happy, and they played happily. Gradually, they became famous in the local area, attracting more and more friends to join their team. Until one day, a guy from another village suddenly came to the door, hoping to connect with them and realize the network battle between villages. Little A said yes, so they found an extra-long network cable to connect the switches of the two villages. It turned out that the two villages could not communicate with each other. Anyway, it turned out that the computer over there was not using the same operating system as theirs, which led to a mismatch in the form of information transmission between them. During this period, people from other villages also came to look for Xiao A, but Xiao A found that the operating system used in each village was different.

router

Fun about switches and routers

In order to solve this problem, the friends of each village sat together and organized a meeting, and finally came up with a solution: adopt the same form of information transmission (like Qin Shi Huang's unified weights and measures). So how to achieve this? The friends stipulate that different villages should first add the same set of protocols to their respective operating systems. When communicating between different villages, the information is processed into a unified form through a protocol and then transmitted through a special device. This device is called a router. The router is addressed by an IP address, and we say that it works at the network layer of the computer.

In this way, through such a series of modifications, Little A finally led the villagers to realize the communication of the entire township. As more and more people in the city joined Little A's agreement, Little A led the villagers to gradually realize communication in the city, the country and even the world. This set of protocols is the TCP/IP suite of protocols, and this is how the Internet was formed.

Fun about switches and routers

Later, the second dog in the next village lost a game with Xiao A, but he was not convinced. He contacted a group of fox friends and dog friends, colluded with them, and sent a message to Xiao A and their village at a fixed time every day, with everything in content, such as "Thunder, rain to collect clothes!" and so on. It made Little A play the game card to death, and finally the network crashed,。 This is known as a "denial-of-service attack" (DoS attack).

防火墙(Firewall)

Fun about switches and routers

So what to do? Clever little E invents a new device. The device monitors the amount of traffic coming in and out of their village's network and can dictate what data can and can't get in and out, thus countering data that poses a threat to the village. They set up a ban on access to Ergouzi's village's data, so that Ergouzi and his friends could not attack Little A's network in their village. Everyone thinks that the two dogs are like fires, and this thing can prevent them, so they named this device Firewall (hardware). Later, Xiao E thought that it would be good if every computer had a firewall, but it was too expensive for every household to buy a firewall, so he taught himself programming and programmed an antivirus software to install on the computer to filter unwanted information, which is the software firewall.

With the firewall, Little A and their village (LAN) don't have to worry about other villages (the Internet) accessing their data at will, and they don't have to worry about the children in their village watching small movies.

Even though the whole network has spread all over the world today, when Little A and his friends in the village are fighting against the Imperial Era, they still use switches. Routers and firewalls are only used when communicating with the larger world outside.

Summary: Switches are suitable for intra-LAN interconnection, routers are used to interconnect the entire network segment, and firewalls are used to filter unwanted data during interaction.

The link between them goes like this: router-firewall-switch, which in turn connects to other network devices.

Fun about switches and routers

The difference between a switch and a router

1. The place of work is different

According to the network architecture division of the OSI model, from the bottom up, the router works at the third layer (network layer), while the switch we often call works at the second layer (link layer) (there are more advanced Layer 3 switches, Layer 4 switches, and even Layer 7 switches)

Fun about switches and routers

2. The working mechanism is different

The main tasks of routers and switches are as follows:

Router: Addressing, Forwarding (relies on IP address)

Switches: Filtering, Forwarding (Depends on MAC Address)

We can see that the main job of these two is to forward data, but the difference is that they rely on different addresses, which is a fundamental difference!

The router has a routing table with its addressing information (like a map), and after receiving the datagram at the network layer, it will forward the datagram to the next station (which may be a router, switch, or destination host) according to the routing table and routing algorithm

There is a MAC table in the switch, which stores the MAC addresses of all devices connected to it, and it will look up the destination MAC address in its own table according to the destination MAC address in the header information of the received data frame, forward if there is one, and give up if not

Let's look at an example of a network topology diagram:

Fun about switches and routers

From the topology diagram we should know:

Each router and the devices connected to it actually form a local area network

The switch works under the router, which means that the switch works within the local area network

The switch is used for data forwarding in the intranet of the local area network, and the router is used to connect the local area network and the external network

Read on