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

Detailed explanation of Vuex environment

Table of contents Build Vuex environment Summariz...

MySQL Basics Quick Start Knowledge Summary (with Mind Map)

Table of contents Preface 1. Basic knowledge of d...

Docker's health detection mechanism

For containers, the simplest health check is the ...

PHP scheduled backup MySQL and mysqldump syntax parameters detailed

First, let's introduce several common operati...

How to use async and await correctly in JS loops

Table of contents Overview (Loop Mode - Common) D...

How to quickly build an FTP file service using FileZilla

In order to facilitate the storage and access of ...

Summary of the top ten problems of MySQL index failure

Table of contents background 1. The query conditi...

Detailed tutorial on installing ElasticSearch 6.4.1 on CentOS7

1. Download the ElasticSearch 6.4.1 installation ...

Detailed explanation of bash command usage

On Linux, bash is adopted as the standard, which ...

Complete steps to enable gzip compression in nginx

Table of contents Preface 1. Configure gzip compr...

How to clear mysql registry

Specific method: 1. Press [ win+r ] to open the r...

In-depth analysis of the Linux kernel macro container_of

1. As mentioned above I saw this macro when I was...

How to use the dig/nslookup command to view DNS resolution steps

dig - DNS lookup utility When a domain name acces...

CentOS method to modify the default ssh port number example

The default ssh port number of Linux servers is g...