Understanding the Router
Nowadays, a router in a household is a pretty common picture. Even though we use it every day, most people remain unaware of the functionality of the router and how it works. So, what is a router, and how it works?
A router links network devices by passing data packets between them. This information can be sent between devices or from devices to the internet. The router does this by allocating a local IP address to each device on the network. If there is an internet gateway connected to the router, the devices connected to the router can access the internet.
To put it simply, a router assigns a unique IP address or private IP address to every device connected to it which makes a local network. That’s how every device has its own identity and inter-communication between the devices are possible. In this condition, devices from the local network can not connect to the internet yet. Routers also provide NAT (Network Address Translation), which overcomes the problem of connecting to the internet. When a device connects to the internet, the NAT service translates its private IP address to a public IP address. As a result, all of those devices can share a single public IP address to connect to the internet. The NAT service may also transform a public IP address into a private IP address, which is necessary when a device connected to the internet wants to communicate with a device linked to this local network.
Concept of Hops
If you are a tech-geek, I am sure you have heard the terms single-hop and multi-hop. So, what is it? Assume there are two routers between hosts A and B. A packet (part of data) must transit through these two routers in order to be transferred from host A to host B. A hop is an event of data moving from one router to another. The hop count denotes the number of routers, switches, or repeaters that a packet goes through on its way from its source to its destination.
So, does the hop count matter? Yes, it is. If a packet has to go through too many routers, then the connection can be slow. Though hop is not the only factor of slow connection, it can play an important part in it.
Well, how can you count hop in a network? There is a cool tool to count the hop named
traceroute which can be used in both windows and linux. To use it, you need to install the package by running the commands below.
$ sudo apt update $ sudo apt install traceroute
The syntax is pretty simple. You just pass the URL of the website or IP address. Check the command below.
$ traceroute enablegeek.com
It traces all the hops to visit enablgeek.com from my location. The traceroute tool supports a maximum of 30 hops. Each step shows you the IP address and time needed to pass the router.
As you may expect, there should be a configuration for how data packets are sent to network devices. The configuration is kept in a kernel structure called a routing table on Linux and UNIX systems. To communicate with other computers on a network, you must modify this table. The routing table supports both static and dynamic routing. The kernel decides which path a packet should take out of numerous existing routes in dynamic routing.
You can check the routing table on your machine by running the
route command. First, you need to install it.
$ sudo apt update $ sudo apt install net-tools
Now, run the command.
$ route -n
We have IP addresses
192.168.0.0 in the destination column. As a result, each packet attempting to reach these devices must pass via wlo1 (wireless network interface). There is also a destination tagged as
0.0.0.0, indicating that it is unknown. What does this mean? If a device tries to connect to
18.104.22.168, which is not in the network, the router transfers the data to a gateway to hunting for on the internet.
The subnet mask is known as
genmask is used to determine which IP addresses correspond to which destinations. There are two flags:
U which indicates that the network is up and is a gateway and network is up, respectively.
Iface is the interface that our packet will be going out of.
You can also add or delete a route to/from the routing table by using the following command.
$ sudo route add -net 192.168.0.1/16 gw 10.11.12.8
$ sudo route del -net 192.168.0.1/16
These actions can be done with the
ip command also.
To add a route,
$ ip route add 192.168.0.1/16 via 10.11.12.8
To delete a route,
$ ip route delete 192.168.2.1/16
Path of a Data Packet
When a data packet is sent from a source, it searches the local network for the destination IP address. If the IP address is located within the local network, we require the destination’s MAC address to deliver the data correctly. To obtain the MAC address, the local network employs the ARP (address resolution protocol), which searches a table to determine which MAC address corresponds to which IP address. The packet may be found at the receiver end after locating the MAC address.
The ARP cannot be used if the destination is not located inside the local network. The packet will then be routed through the default gateway. The transmitted packet has a source IP address, a source MAC address, and a destination IP address in this place. Finally, the gateway locates the target IP address outside of the local network and determines its MAC address within the local network. That is how the package was transmitted.
It would be inconvenient to have to individually establish routes on a routing table for each device on your network, so we utilize routing protocols instead. Routing protocols aid in the effective and efficient communication of computer networks. These protocols, regardless of network size, can assist in the safe delivery of data to its intended destination. Understanding the many types of routing protocols might help you decide which one to utilize. In this part of the article, we will discuss the different types of routing protocols available.
Before delving into routing protocols, one crucial concept must be addressed. When communicating with another router, both routers collect information about the other router. Convergence, also known as routing convergence, occurs when a group of routers in a shared network has the same topological knowledge. The routing protocol is used by the routers in the network to exchange topological information. Convergence occurs when all routers provide routing information to all routers in the network.
Distance Vector Protocol Routing (DVP)
Based on the distance, DVR routing systems choose the optimal route to a given destination. Although the distance is often defined in hops, it might instead be quantified in terms of latency, packet loss, or another equivalent metric. If the distance measure is a hop, then a hop is regarded to have been traveled each time a packet passes through a router. If router A is 5 hops away and there is another router B that is close to A, only one hop away, then router B is 4 hops away. It is determined that the route with the fewest hops to a certain network is the optimal path there.
DVR is great for small-scale networks. As it periodically sends the routing table to another network, for larger networks it takes much time to converge. One of the popular DVR protocols is Routing Information Protocol (RIP) which sends a routing table every 30 seconds. So, as you can imagine, for a bigger network it will take a huge amount of time. Another thing is that it chooses the next router based on the least amount of hops which may not always be the efficient one.
Link State Routing Protocol
Unlike DVR, link state protocols are great for a large network, as it does not sends the information of the routing table periodically. There are basically three tables for a router that has link state protocols enabled. The first one stores the information about the directly connected neighboring routers, the second one has info about the entire topology of the network and the last one is the actual routing table. OSPF (Open Shortest Path First) is one of the popular link state protocols; it only updates the routing tables in the event of a network change. There is no hop restriction on it.
Border Gateway Routing Protocol
Internet is a connection of a huge number of smaller networks. Each smaller network consists of multiple routers which are run by a single administration or company or university. This smaller network is known as autonomous computers (AS). BGP makes it possible for the internet to transmit routing data between AS. Networks require a method of communication as they interact with one another. Peering allows for the accomplishment of this. Peering is made feasible through BGP. Without it, networks could not communicate with one another to send and receive data.
Each AS requires a registered autonomous system number (ASN) in order to share routing data. t is like a local mailbox. IGP (Interior Gateway Protocol) protocols like RIP and IGRP are often used within the same autonomous system or the same organization. Exterior Gateway Protocols (EGP) is used to establish communication between two autonomous systems. BGP is the name of the protocol that is used to communicate across the internet or between two distinct autonomous number systems. The sole protocol used to exchange routes between two independent autonomous number systems and run on the backbone of the internet is BGP. The BGP protocol is used by internet service providers to manage all route data.