On the Internet, all information is transmitted in the form of small blocks of data – the so-called packets. The packet itself consists of the start bits, header, trailer, and payload – each such block with data is transmitted along a specific route, which, in turn, is determined by the router. The network route is "laid" based on the information received from the routing tables according to the routing protocols and instructions of the network administrator.
Routing tables contain the parameters necessary for the correct identification and reading of the network route. They contain the following sections:
Also, optionally, the sender's address, the size of the TCP window, and the maximum packet size can be specified in the routing table. All this makes it possible to optimize data transmission within the network. Later in the article, we will tell you how to manage Linux routing and share useful configuration recommendations.
Routing Management for Linux OS is carried out with three commands:
Let's look at some basic examples of using these commands in Linux.
ip route show
These commands allow you to view the routing table or some of its individual elements.
In this case, the route command can only be used to get information in full numeric form, but it will not be possible to configure routing policies with it. The ip command should be used for this purpose. For example:
ip route add 172.16.10.0/24 via 192.168.1.1 – add a route through the gateway;
ip route add 172.16.10.0/24 dev eth0 – add a route through the interface;
ip route add 172.16.10.0/24 dev eth0 metric 100 – a route with a metric.
There is also the possibility of creating a "zeroed" route, and packets passing through it will be automatically deleted due to "No route to host". To do this, use the command:
ip route add blackhole 10.56.50.0/27
It is recommended to use it for DOS attacks from the host.
As we noted above, the add command allows you to add routes. But this is not the only possible operation, there are three others:
Imagine that you have two offices connected to each other via an IP tunnel. One office has an IP address of 192.168.1.4, and the second one has an IP address of 192.168.1.6. To connect a local network between them, you need to register the command on the second router:
route add -net 172.16.10.0/24 gw 192.168.1.4
As a result, you will connect the gateway "192.168.1.4" for the network "172.16.10.0/24". After that, we prescribe the following on the first router:
route add -net 172.20.0.0/24 gw 192.168.1.6
As you can see, everything is quite simple and transparent.
To change the LAN of the second router, we simply delete the old entry:
route del -net 172.20.0.0/24 gw 192.168.1.6
And then add a new route on the first router:
Static routing configs will be located in different directories, depending on the distribution used:
In them, you can also set certain settings and parameters for routing. If you have any questions, please contact our specialists via Livechat.