What is routing: Building routing tables in Linux
Vladimir Lebedenko
I will help you build geo diversified and fault-tolerant server infrastructure for your business. DM me to learn how.
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.
Commands for viewing the routing table
Routing Management for?Linux OS?is carried out with three commands:
Let's look at some basic examples of using these commands in Linux.
route -n
netstat -rn
ip route show
cat /proc/net/route
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.
ip route add blackhole 10.56.50.0/27
?It is recommended to use it for DOS attacks from the host.
领英推荐
Commands for actions with routes
As we noted above, the add command allows you to add routes. But this is not the only possible operation, there are three others:
Examples of static routing
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
route add -net 172.20.0.0/24 gw 192.168.1.6
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
route add -net 172.20.0.0/24 gw 192.168.1.6
Where are the configuration files located
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.