Understanding Routing Table

Q.What is a routing table? Can you explain its usage under Linux / UNIX operating system?

A. Almost all computers and network devices connected to Internet use routing tables to compute the next hop for a packet. It is electronic table that is stored in a router or a networked computer. The routing table stores the routes (and in some cases, metrics associated with those routes) to particular network destinations. This information contains the topology of the network immediately around it. The construction of routing table is the primary goal of routing protocols and static routes.

Each Linux / UNIX / Windows or any computer that uses TCP/IP need to make routing decision. Routing table is used to control these decisions. To display routing table type the following command at UNIX / Linux shell prompt:
$ netstat -r -n
$ route -n
Sample output:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface   U     0      0        0 eth0   U     0      0        0 ra0     U     1000   0        0 eth0         UG    100    0        0 ra0

If you are using Windows Server type the following at a command prompt:
c:> route print
Flag G indicates path to route packets via a gateway. If you would like to visit yahoo.com from your computer you need to go via gateway. This usually means that you have to set up a static route to the gateway beforehand. If you specify the address of one of your local interfaces, it will be used to decide about the interface to which the packets should be routed to. metric field used by routing daemons. This is required on large LAN and wan setups. The output of the kernel routing table is organized in the following columns:

  • Destination : The destination network or destination host.
  • Gateway : The gateway address or ’*’ if none set.
  • Genmask : The netmask for the destination net; for a host destination and for the default route.
  • Flags : Possible flags include
    • U (route is up)
    • H (target is a host)
    • G (use gateway)
    • R (reinstate route for dynamic routing)
    • D (dynamically installed by daemon or redirect)
    • M (modified from routing daemon or redirect)
    • A (installed by addrconf)
    • C (cache entry)
    • ! (reject route)
  • Metric : The distance to the target (usually counted in hops). It is not used by recent kernels, but may be needed by routing daemons.
  • Ref : Number of references to this route. (Not used in the Linux kernel.)
  • Use : Count of lookups for the route. Depending on the use of -F and -C this will be either route cache misses (-F) or hits (-C).
  • Iface : Interface to which packets for this route will be sent.
  • MSS : Default maximum segment size for TCP connections over this route.
  • Window : Default window size for TCP connections over this route.
  • irtt : Initial RTT (Round Trip Time). The kernel uses this to guess about the best TCP protocol parameters without waiting on (possibly slow) answers.
  • HH (cached only) : The number of ARP entries and cached routes that refer to the hardware header cache for the cached route. This will be -1 if a hardware address is not needed for the interface of the cached route (e.g. lo).
  • Arp (cached only) : Whether or not the hardware address for the cached route is up to date.

Your routing table is created automatically, based on the current TCP/IP configuration of your Linux / UNIX computer. You can manually add / modify / edit routing table using route and ip command. The types of entries in a routing table:

  • Network Route: A route (path) to a specific Network ID in the internetwork.
  • Host Route : A route to a specific internetwork address (Network ID and Host ID). Host routes allow intelligent routing decisions to be made for each network address. Host routes are used to create custom routes to control or optimize specific types of network traffic.
  • Default Route: A route that is used when no other routes for the destination are found in the routing table. If a router or end system (such as a PC running Microsoft Windows or Linux), cannot find a route for a destination, the default route is used. The default route is used if no other host or network route matches the destination address. Please see related FAQs below for more examples of route and ip command.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 11 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
11 comments… add one
  • anand vamsi Oct 18, 2011 @ 18:25

    nice article informative

  • Sean Nov 12, 2011 @ 15:56

    Good article! Thanks!

  • Hemanth Apr 13, 2012 @ 2:52

    same comment…’pretty informative’..

    thanks for this..

  • Ellison Daw Apr 25, 2012 @ 12:38

    I am trying to get a better understanding of the concept of routing tables in an ip network . I did find this basic information useful and will really appreciate and more such information that is sent to me .

  • Eddie Nov 13, 2012 @ 11:57

    I am looking for the basics not the informations you giving, but thank you

  • Rohan Nov 17, 2012 @ 18:16

    can you please elaborate more on default routes?

  • zahra Jan 3, 2013 @ 8:01

    hello, thanks for this

  • Zazarian Feb 6, 2013 @ 10:23

    “-Network Route: A route (path) to a specific Network ID in the internetwork.
    -Host Route : A route to a specific internetwork address (Network ID and Host ID).”

    Can you tell me the difference between these two definition ?

  • Andres Sep 2, 2014 @ 20:59

    Good article.
    Thank you very much!.

  • Kenn Dillon Jan 12, 2015 @ 15:08

    Being a novice I need more. You tell what the Flag basic definitions are, but that still doesn’t tell me which are good flags to see and which are bad. Further information that explains what each of those flag readings mean would be helpful.

    I suspect my readings are good, since every diagram I have seen show the flags to be either: U, UH or UG, and my flags are shown as UH, U and U.

  • Agustino Thadeus Feb 25, 2017 @ 10:49

    Very informative article, made things much clearer

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum