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 install mysql on centos and set up remote access

1. Download the mysql repo source $ wget http://r...

An article teaches you how to implement a recipe system with React

Table of contents 1. Recipe Collection 1.1 Projec...

How are Vue components parsed and rendered?

Preface This article will explain how Vue compone...

How to upgrade CentOS7 to CentOS8 (detailed steps)

This article uses a specific example to introduce...

js to achieve simple drag effect

This article shares the specific code of js to ac...

Let's talk about bitwise operations in React source code in detail

Table of contents Preface Several common bit oper...

Detailed explanation of the available environment variables in Docker Compose

Several parts of Compose deal with environment va...

nginx proxy_cache batch cache clearing script introduction

Preface: I used the official nginx proxy_cache as...

Analysis and application of irregular picture waterfall flow principle

The layout problem of irregular picture walls enc...

The latest graphic tutorial of mysql 8.0.16 winx64 installation under win10

In order to download this database, it takes a lo...

CSS3 click button circular progress tick effect implementation code

Table of contents 8. CSS3 click button circular p...