**What are routes and routing tables in Linux? **
The process of routing means that IP packets are transmitted from one point to another on the network. When you send an email to someone, you are actually transmitting a series of IP packets or datagrams from your system to another person's computer. The data packet sent from the computer reaches the target computer system through several gateways or routers. The same method applies to all internet protocols, such as HTTP, IRC and FTP.
In all Linux and UNIX systems, information about how to forward IP packets is stored in the kernel structure. These structures are called routing tables. When you want the system to communicate with other computers, you may need to configure these routing tables. First of all, it is very important to understand how to view these routing tables on a Linux system.
In this article, we will explain how to view the routing table in Ubuntu through the following three commonly used commands:
We ran the commands and procedures mentioned in this article on the Ubuntu 18.04 LTS system.
We use the Ubuntu command line terminal to run the above commands. You can open the terminal through the system Dash or Ctrl + Alt + T shortcut.
**How to view the routing table? **
Method 1: Via netstat command
The netstat command has always been a widely used method for printing routing table information in Linux. However, it was officially replaced by the ip route command. In any case, we all need it because it is still a way to retrieve the required information.
Here is how to use this command:
$ netstat -rn
This is the output:
Destination This column indicates the destination network.
Gateway This column indicates the defined gateway of the network. If you see * in this column, it means that the specified network does not require a forwarding gateway.
Genmask This column indicates the netmask of the network.
The U output in this column of Flags indicates that the route has been activated. The G output indicates that the specified gateway should be used for this route. D stands for dynamic installation, M stands for modification, and R stands for recovery.
MSS This column indicates the default maximum segment size (MSS) of TCP connections for this route.
Window This column indicates the default window size of TCP connections on this route.
Irtt This column indicates the initial round-trip time of this route.
The IfaceIface column shows the network interface. If you have multiple interfaces, you will see lo (for loopback), eth0 (for the first Ethernet device) and eth1 (for the second Ethernet device), and so on the number of interfaces you have installed .
Method 2: Via route command
The route command is also a widely used but now obsolete command to view the routing table. The man page for this command also mentions that this command has now been replaced by the ip route command.
With this command, you can view the exact same information with the netstat command. Here is how to use it:
$ route -n
Core IP routing table
Target gateway subnet mask mark hop reference use interface
0.0.0.0 192.168.182.2 0.0.0.0 UG 20100 0 0 ens33
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 ens33
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.182.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
Method 3: Via ip route command
Last but not least, this is the best way to print routing table information in Linux. Here is how to use this command:
$ ip route
Although this information is not as reader-friendly as the previously mentioned commands, it is still sufficient for you to configure the router.
These are several commands to view routing table information in Ubuntu. Although the ip route command is not very neat in appearance, it is still the recommended way to find relevant routing table information. Although other commands are considered obsolete, they do sometimes help export what needs to be extracted.
to sum up
The above is the entire content of this article. I hope that the content of this article has a certain reference value for your study or work. If you have any questions, you can leave a message and exchange. Thank you for your support to ZaLou.Cn.
Recommended Posts