≡ Menu

IP Routing: Linux Route Flags (U – Up, G – Gateway, H – Host)

In the previous article of this series, we discussed about the basic principles of IP routing and the steps involved in IP routing.

In this article we will look a bit closely at some of the other aspects related to IP routing.

Linux IP Routing series: part 1, part 2, part 3 (this article).

Lets start the discussion with the explanation of flags in the routing table entries.

The flags

Following is the list of flags and their significance in the routing table :

  • U : This flag signifies that the route is up
  • G : This flag signifies that the route is to a gateway. If this flag is not present then we can say that the route is to a directly connected destination
  • H : This flag signifies that the route is to a host which means that the destination is a complete host address. If this flag is not present then it can be assumed that the route is to a network and destination would be a network address.
  • D : This flag signifies that this route is created by a redirect.
  • M : This flag signifies that this route is modified by a redirect.

Direct route, Indirect route and the ‘G’ flag

  • A direct route is the one where the destination is directly connected to the forwarding host while in case of an indirect route the destination host is not directly connected to the forwarding host.
  • On a direct route the destination IP address and the link layer address in the datagram are that of the destination host while in case of an indirect route, the destination IP in the datagram remains unchanged but the link layer address changes to that of the next router to which this datagram is being delivered.
  • This is where the ‘G’ flag comes in handy. The ‘G’ flag above signifies that this is an indirect route. For a direct route, the ‘G’ flag is not set.

The ‘G’ flag Vs the ‘H’ flag

Now as we all know that the ‘G’ flag signifies the route. The route could be direct or indirect as explained above.

But the ‘G’ flag should not be confused by the ‘H’ flag. This flag signifies that the destination address in the entry is a host address or a network address.

As already discussed in the previous part of this article series, when the destination IP address from the received datagram is searched in the routing table the first the complete address is matched.

If complete address matching fails then the network ID is matched to see if the routing table has an entry for a network to which the destination IP address of the datagram belongs.

So we see that in case of a complete IP address match the entry would contain ‘H’ flag while in case of network ID match the entry would not contain the ‘H’ flag.

Routing table complexity

A routing table can be fairly straight forward as well as can be really complex. The complexity of a routing table depends on the topology of the network to which the host talks to. Lets consider some practical cases and see how they influence the routing table of a host.

  • A very basic case would be that of a stand alone host that is not at all connected to any network. In this case the TCP/IP stack can still be used by the host but in case of communication to itself only. So in this case the routing table would contain a single entry and that will be of loop back interface.
  • For a host connected to a single LAN, the routing table would contain a couple of entries. One entry (as already discussed above) would that be of loop back interface while the other entry would that be of the LAN .
  • Now, suppose the host is connected to Internet. In this case the router table will contain(besides the loop back entry) an entry for the default router through which the host is connected to the Internet.
  • If the host is connected to various networks through different interfaces then the routing table would contain individual entries for all the different networks to which the host is connected. Besides there will be a loop back entry and there could be a default router entry.

Routing Table Initialization

Till now we have been discussing about the routing table entries, what they contain, their complexity etc. Now lets discuss briefly over the creation of these entries.

  • When an interface is initialized, an entry for a direct route is created in the routing table corresponding to that interface.
  • Routes to networks and hosts that are not directly connected can be added through commands.
  • ‘route’ command is used for this purpose.
  • For example, a basic route command would look like : route add <destination> <gateway> <metric>
  • If the ‘metric’ is non zero then ‘G’ flag is set else not.

This route command can be triggered from the initialization files when the system boots up. The problem here is that there is not one standard file which is used across all the OS’s that contains route command. Under 4.4BSD and BSD/386 it is /etc/netstart, under SVR4 it is /etc/inet/rc.inet, under Solaris 2.x it is /etc/rc2.d/S69inet, SunOS 4.1.x uses /etc/rc.local, and AIX 3.2.2 uses /etc/rc.net.

There are a couple of others ways to initialize a routing table. Like running a routing daemon or to use router discovery protocol but we will not elaborate those in this article.

NOTE: You should also understand how to use the route command effectively.

ICMP host or ICMP network unreachable errors

These errors occur when the host or the network (for which the IP datagram is destined to) are down. For example, suppose host A is connected to host B and link to host B is down.

Then in this case if the host A receives an IP datagram for host B then host A will send a ‘host unreachable’ error back to the host from where this IP datagram originated.

This case assumes that no default router entry exists on host A. Same goes for the ‘network unreachable’ error.

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 3 comments… add one }

  • Anonymous May 4, 2012, 5:30 am

    A typo in flags listing:
    M : This fag…. : *flag

  • bob May 4, 2012, 7:29 am

    might be good to put the example output at the top of the page (eventhough it is given in part 1/2), so that it is easier to follow.

    As usual, learnt something today. Good work!!!

  • Ramesh Natarajan May 4, 2012, 11:02 pm


    Thanks for pointing out the typo. It is fixed now.

Leave a Comment