How to view the network routing table in Ubuntu

How to view the network routing table in Ubuntu

What are Routing and Routing Table in Linux?

The process of routing means the transmission of IP packets from one point to another on the network. When you send someone an email, you are actually transmitting a series of IP packets, or datagrams, from your system to the other person's computer. Data packets sent from a computer pass through several gateways or routers to reach the destination computer system. The same approach applies to all internet protocols such as HTTP, IRC, FTP, etc.

In all Linux and UNIX systems, information about how to forward IP packets is stored in kernel structures. These structures are called routing tables. You may need to configure these routing tables when you want your system to communicate with other computers. First, it is 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 by going through the following three commonly used commands:

  • netstat Command
  • route command
  • ip route command

We have run the commands and procedures mentioned in this article on an Ubuntu 18.04 LTS system.

We use the Ubuntu command line, the Terminal, in order to run the above commands. You can open the Terminal through the system Dash or the Ctrl+Alt+T shortcut.

How to view the routing table?

Method 1: Using the netstat command

The netstat command has been a widely used method to print routing table information in Linux. However, it was officially replaced by the ip route command. We need it regardless, as it is still a way to retrieve the information we need.

Here’s how to use this command:

$ netstat -rn 


-r This flag is used to display the kernel routing table


-n This flag is used to display numeric addresses


This is the output:

Destination This column indicates the destination network.
Gateway This column indicates the defined gateway for the network. If you see a * in this column, it means that the specified network does not require a forwarding gateway.
Genmask This column indicates the network's network mask.
Flags A U output in this column indicates that the route has been started. 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) for TCP connections for this route.
Window This column indicates the default window size for TCP connections on this route.
Irtt This column indicates the initial round trip time for this route.
Iface The Iface column displays the network interface. If you have multiple interfaces, you’ll see lo (for loopback), eth0 (the first Ethernet device), and eth1 (for the second Ethernet device), and so on for the number of interfaces you have installed.

Method 2: Using the route command

The route command is also among the once widely used but now obsolete commands to view routing tables. The man page for this command also mentions that this command has now been replaced by the ip route command.

This command lets you view the exact same information as you can with the netstat command. Here’s how to use it:

$ route -n 


Kernel IP routing table

Destination Gateway Subnet Mask Flags Metric 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 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

-n This flag is used to display numeric addresses only

Method 3: Using the ip route command

Last but not least, here is the best way to print routing table information in Linux. Here’s how to use this command:

$ ip route 


While this information is not as reader-friendly as the previously mentioned commands, it is still enough for you to configure your router.

Here are a few commands to view routing table information in Ubuntu. While the ip route command is not very neat in appearance, it is still the recommended way to find relevant routing table information. While the other commands are considered obsolete, they do sometimes help to export what needs to be extracted.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of Ubuntu 14.04 bridge network settings and SSH login
  • How to troubleshoot network problems in Ubuntu
  • Ubuntu 10.10 network configuration
  • How to modify network configuration using Ubuntu command line
  • Solution to Ubuntu not being able to connect to the Internet
  • Solution to the problem that Ubuntu cannot connect to the Internet in the virtual machine
  • Solution to the problem that the virtual machine Ubuntu 16.04 cannot connect to the Internet
  • Solution to the problem of being unable to access the Internet after Ubuntu restarts in VMWare
  • How to connect Ubuntu server to the external network on VMware
  • Solution to Ubuntu 18.04 not being able to connect to the network in VMware virtual machine

<<:  Install and configure MySQL under Linux

>>:  Problems with index and FROM_UNIXTIME in mysql

Recommend

How to view the creation time of files in Linux

1. Introduction Whether the creation time of a fi...

HTML pop-up div is very useful to realize mobile centering

Copy code The code is as follows: <!DOCTYPE ht...

Solve the problem of docker log mounting

The key is that the local server does not have wr...

Vant+postcss-pxtorem implements browser adaptation function

Rem layout adaptation The styles in Vant use px a...

Detailed explanation of the use of HTML header tags

HTML consists of two parts: head and body ** The ...

Summary of the characteristics of SQL mode in MySQL

Preface The SQL mode affects the SQL syntax that ...

Nginx reverse proxy forwards port 80 requests to 8080

Let's first understand a wave of concepts, wh...

HTML table markup tutorial (5): light border color attribute BORDERCOLORLIGHT

In a table, you can define the color of the upper...

A Brief Analysis of Subqueries and Advanced Applications in MySql Database

Subquery in MySql database: Subquery: nesting ano...

Example analysis of the use of GROUP_CONCAT in MySQL

This article uses an example to describe how to u...

Example of using rem to replace px in vue project

Table of contents tool Install the plugin Add a ....

Introduction to the role of HTML doctype

Document mode has the following two functions: 1. ...