The Internet is a wonderful world of different jobs (or roles) that allow billions of devices to communicate together. In this article, we’ll delve into some of the key players in the Internet and break down what they accomplish on the web.

What follows is not the whole story, but it is sufficient to cover the flow of packets across the Internet.

Host the Host

A host usually refers to the end of the entire Internet. Any device that serves as a starting point or an end point in Internet communication can be called a host.

The traditional example is the home computer or laptop. But in modern times, terminals have many more forms: smart phones, smart TVS, smart watches, and even refrigerators.

Hosts interact with users through software and applications, and they sometimes need to do some transmission over the line. Therefore, we can say that the host runs in all seven OSI models.

A very typical example of network communication is two hosts one acting as a client and one as a server. The client is the originator of the request and it needs some information or data. The server is the receiver of the request, and it has the information, the data, that the client needs.

Internet Network

A network is two or more devices that are grouped together for the same purpose or in a physical form. The Internet can take many forms, such as:

  • Multiple computers in the computer room belong to the same network
  • Every computer, cell phone, or printer in the house is connected to the same physical address and belongs to a network.
  • WIFI in coffee shops allows consumers to connect to the same WIFI network
  • Large companies may use multiple networks, with different work roles using different networks.

Devices on a network can communicate with devices on the same network or on different networks for different purposes.

Switch the Switch

The main purpose of the switch is to forward messages within the network.

The switch operates at Layer 2 of the OSI model, so it only looks at layer 2 headers. The second layer contains information that you need to ensure hop to hop, such as the source and final MAC address.

The switch runs by maintaining something called a MAC address table. This table maps MAC addresses to inserted switch ports.

MAC Address table Fills the source MAC address field of the received frame.

To forward frames, the switch looks for the MAC address of the destination in the address table to decide which port to use.

If the exchange reaches a MAC address it does not know the path to, it will be copied and flood out through all the ports.

Router, the router

A router is a network device used primarily to communicate between different networks. Each interface of the router creates a network boundary. The router runs at Layer 3 of the OSI model, which means it only cares about layer 3 headers. Layer 3 contains information that needs to be implemented end-to-end, such as IP addresses.

In the figure above, router R1 and router R2 are divided into three networks. (11.11.11.x, 22.22.22.22.x, and 33.33.33.x) The right port of R1 and the left port of R2 are on the same network.

The only way to send data from 11.11.11.x to 33.33.33.x is to forward the packet to R1, then to R2, and finally to the target server.

The router does this through a routing table. This table contains all known paths to be reached. These paths are called routes, and each route includes an IP address and an interface or IP address that points to the next routing address. Remember, from each router’s point of view, the routing table maps every network that exists. If a packet is received destined for an unknown path, the destination network does not exist for the router. Therefore, when a router receives a packet to send to a network that does not have a routing table, the packet is discarded.

Address Resolution Protocol (ARP)

Before we talked about MAC addresses at layer 2 and IP addresses at Layer 3, what about linking MAC and IP? The answer is the address resolution Protocol, ARP.

In general, when two hosts communicate. They already know each other’s IP addresses. There are many ways to know the IP address of the other party, sometimes provided by the user, sometimes by other protocols (such as DNS).

However, they do not know each other’s MAC addresses. Therefore, the host uses ARP to obtain the MAC address of the peer. In other words, ARP uses known IP addresses to explore unknown MAC addresses. The results of the exploration are stored in the ARP table, which maps IP and MAC addresses.

The following figure Bridges layer 2 and layer 3 and shows how ARP works:

There are three networks in the image above: the purple network, the grey network and the red network. We use this diagram to describe two ARP instances: the first instance communicates with a host in the network (client to the purple server). The second instance is communicating with hosts on different networks (client to red server).

When a client needs to communicate with a purple server, it knows the IP address of the purple server, so it knows that it is on the same network. When a client attempts to communicate with a host on the same network, the client sends an ARP request to the MAC address of the host.

After the ARP request is completed, the packet header is as follows:

When the client communicates with the red server, it knows the IP address of the server, so it knows that the server is not on the same network, so the packet is sent to the nearest router, also known as the default gateway.

The client usually has a default gateway set, which is R1 in the figure above. When the client attempts to communicate with the host outside the network, the client sends an ARP request to the MAC address of the default gateway.

The header of the packet is as follows:

To summarize the behavior of ARP:

  • When a client talks with a host on the network, ARP requests are sent to the MAC address of the host.
  • When a client talks with a host outside the network, ARP sends an ARP request to the MAC address of the default gateway.

ARP helps clients create layer 2 headers based on layer 3 headers to move packets from one to the next hop.

It should also be noted that any device intended to forward packets based on the IP address (Layer 3) must have the ability to transmit packets to the next hop (Layer 2).