🌐 🇵🇱 Polski · 🇬🇧 EN
Routing in computer science means determining the path and sending data packets along it within computer networks. The goal of routing is to deliver a packet to its destination as optimally as possible. Initially, the only criterion was having the most accurate path to the destination. Today, routing protocols can also consider parameters such as packet priority, traffic congestion in specific network segments, etc., when selecting a path. If you have a system with two or more network interfaces, you must choose which one will direct the traffic and how. By running the "route" command, we can display the current routing path and change it if necessary.
Path determination is the process of directing packets through a labyrinth of various networks located between the source and the destination. In TCP/IP systems, this is like asking for directions in an unknown country. The first person you meet might point you toward the right city. Once you reach that city, the next person will be able to tell you how to get to the right street, and if you are very close, someone will point out the building you are looking for.
The word "routing" is commonly used to denote two things:
The word "routing" is commonly used to denote two things:
- searching for an address in the routing table to be able to forward a packet to its destination
- creating a routing table
ROUTING TABLES
To see the routing table of a system, we run the netstat -r command. We can also add the switch netstat -rn, which will skip DNS lookups, and all information will be presented in numerical form, which is generally more useful.
More information about the netstat command will be provided in subsequent parts.
The Destination field usually contains the network address, the Gateway field must contain the full IP address of the local network interface or a neighboring host; In the case of the Linux kernel, 0.0.0.0 can be used here to invoke the default gateway.
Tables can be configured statically, dynamically, or using a combination of these two methods. A static route is a route created directly using the route command. Static routes should remain in the routing table until the computer is shut down; They are most often configured during system startup by one of the startup scripts.
In a stable local network, static routing is efficient, easy to manage, and reliable. This solution requires the administrator to have thorough knowledge of the network at the time of system startup, and its topology must not change frequently.
Configuring static routes
The route command is used to define static routes, explicit entries in the routing table that never change, even after a routing daemon is started. When adding a new computer to a local network, it is usually sufficient to set only the default route.
Routing takes place at the IP layer. When a packet arrives destined for another computer, its destination IP address is compared with the routes stored in the kernel's routing table. If the address matches a route in the table, the packet is forwarded to the IP address of the next gateway associated with that route.
Two special situations may occur during packet forwarding:
- The first occurs if the packet can be delivered to a computer connected directly to the same network. In such a situation, the next gateway address in the routing table will be the interface of one of the local hosts, and the packet will go directly to its destination. This type of route must be entered directly into the routing table manually when configuring the interface using the ifconfig command.
- The second case occurs when none of the routes in the table match the destination address. In such a situation, the default route (if it exists) is invoked; otherwise, an ICMP message is returned to the sender stating that the given network or host is unreachable ("network unreachable" or "host unreachable").
Many local networks have only one exit to the outside world, so we only need one default route pointing to that exit. In internet backbone networks, routers do not have default routes, and if a destination does not have its own entry in the routing table, it is unreachable.
Each route command adds or removes one route. It is one of those handy Unix commands that works on all systems but has a slightly different syntax in each of them.
Route command syntax: route [options]
route - display and manipulate the IP routing table (the "route" program itself is currently considered obsolete, and its successor is "ip route")
route - display and manipulate the IP routing table (the "route" program itself is currently considered obsolete, and its successor is "ip route")
Options:
- add - add a routing route
- del - remove an existing routing route
- flush - clear all temporary routes
- target - destination network or host. Provided as an IP address or network name
- -net - the target is a network
- -host - the target is a host
Examples:
route add -net 127.0.0.0
Adding a loopback entry with a mask of 255.0.0.0 and associating it with the "lo" device (the loopback device must be set up beforehand using ifconfig)
route add -net 192.56.76.0 netmask 255.255.255.0 dev eth0
Adding a default routing route to the 192.56.76.x network via the "eth0" interface.

Comments