Gateways

Topics · Published 2019-08-08 · Revised 2026-11-23
Reviewed corrections applied locally; original wording preserved separately · Joomla source

8,399 Total views across this article’s versions; includes the historical baseline where available.

In an IP route, a gateway is a next-hop router used to reach destinations beyond the directly reachable link. That link can be physical or virtual. This article explains how to recognize gateway routes and distinguish them from local delivery.

Analyzing the output of network route inspection tools such as ip route, route, and netstat will allow you to identify network gateways. The details of how to use those tools are discussed in several other articles on this website, including:

Identifying a Gateway

Let’s briefly review the headers in the route command’s output:

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface

In the legacy display, Destination and Genmask identify the destination prefix. Gateway identifies the next-hop address, while Flags summarize route properties. Metric and interface also matter when interpreting a route. See the netmask discussion for range calculations.

You will encounter three (3) common flags over and over in routing table displays from route or netstat. They are:

  • G: use a gateway.
  • H: the destination prefix identifies one host.
  • U: the route is up.

Direct vs. Indirect Routes

A direct route reaches its destination through an attached link without naming another IP router as the next hop. An indirect route uses a gateway. H does not imply direct delivery: a host route can also carry G. U is a route flag, not an active test that a gateway or an Internet destination is reachable. These meanings are documented in route(8).

Gateway Column vs. Gateway Flag

The layout of routing table displays can cause confusion. Depending on which tool you are using to view router tables, the gateway column will display as one of the following four (4) values for each route:

IPv4 address IPv4 address of the forwarding router (gateway)
0.0.0.0 Unspecified or empty
* Abbreviation for 0.0.0.0
hostname Domain Name of forwarding router on local network

What is the significance of the Gateway column versus the presence or absence of a Gateway flag?

You need both. The gateway column value in the routing table display identifies the IPv4 address of the gateway for the associated network route. And the gateway flag (G) must be present for the route.

Here’s a list of requirements to help clarify:

  • A valid IPv4 address must be specified for the gateway address
  • An empty gateway value (0.0.0.0 or *) is valid, but the route is not a gateway
  • If the Gateway flag (G) is not present, the route is not a gateway
  • If the Gateway flag (G) is present, the gateway column must contain a valid IPv4 address, and cannot be 0.0.0.0
  • The Up flag (U) describes route state; it does not prove end-to-end reachability
  • The device pointed to by a valid gateway route must be a forwarding router

0.0.0.0

Read 0.0.0.0 in the context of its column. Destination 0.0.0.0 together with netmask 0.0.0.0 denotes the default prefix, /0. A zero destination with a different mask can describe a narrower range. In the Gateway column, zero means no next-hop gateway is specified.

A route without a gateway may describe an attached network, a point-to-point interface, or local delivery. It does not by itself prove a physical LAN topology.

Local Area Network (LAN) Connections

On a typical Ethernet LAN, a connected-prefix route has no gateway and sends directly through the listed interface. The U flag and an empty gateway column alone do not establish that every destination is reachable, or that the interface is physical.

The Loopback Adapter

The loopback interface, usually named lo, supports IP communication within the host. It is a virtual interface, not a gateway to another network. Routes of type local direct matching traffic to local delivery.

The Local Routing Table

The local table has ID 255. The usual IPv4 priority-0 rule consults it first, before main (254) and default (253). Table IDs identify tables; rule priorities determine their lookup order. The rt_tables name file does not schedule them. See ip-rule(8) and the table-name discussion.

The kernel maintains routes for the host’s own addresses and broadcasts. These include addresses on ordinary network interfaces, not just loopback addresses.

Friends Do Not Let Friends Modify Their Local Routing Table

The kernel-managed local table is normally best left to address configuration. Special-purpose local routes can be placed in another table, but that table still needs an appropriate policy lookup. Merely naming lo does not make an arbitrary route equivalent to a local-delivery route.

Now You See It, Now You Do Not

The legacy route and netstat -r displays are not a complete policy-routing inventory. Use ip -4 route show table local to inspect local routes, ip -4 route show table all for all IPv4 tables, and ip -4 rule show for the policy order.

ip -4 route show table local

It Is for Me! (localhost)

The address 127.0.0.1 is a loopback address. A packet routed for local delivery can reach an appropriate local socket. There is no separate “localhost process” that receives all such traffic. Routing, transport protocol, and socket binding each play a part.

Examples

Here are a few different examples to help reinforce the concepts described in this article.

Default Route Re-Cap

A routing table does not require a default route. A default prefix covers all destinations in its address family but loses to more specific eligible routes in the same table. It may name a gateway, use a suitable direct interface, or have a terminal route type such as unreachable.

A Basic Gateway Example

Suppose you have a simple network with two entries in your main routing table. One is the route for the local network, which tells the kernel which IP addresses are directly reachable. And the second is the “default gateway,” which tells the kernel in order to reach the rest of the Internet, traffic should be sent to the gateway. The gateway must be a router or firewall device.

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0

The first row describes the connected 192.168.1.0/24 network on eth0. The second is a default route through 192.168.1.1. Without -n, the legacy command may resolve names, producing a display like this:

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
default hostname * UG 0 0 0 eth0

One or the other can be easier to read, depending on your preferences. In the output above, notice on the first line, the gateway IPv4 address (0.0.0.0) is replaced with an asterisk (*). This signifies there is no gateway associated with that route. This is just a different way of representing the same information. Likewise, the second line now shows default as the destination and has a gateway flag (G flag).

Regardless, there’s only one line comprising the entire default route path. The 2nd line in both examples tells us:

  1. This route represents the default network path
  2. The default path points to a gateway (router) named hostname at IPv4 address 192.168.1.1
  3. Any packet not already captured by a more specific addressable route will be routed to the gateway (default route)

There are two crucial pieces of information to note:

  1. If a route represents a gateway, it will have an IPv4 address under the Gateway column AND the G flag must be set under the Flags column
  2. In this default-route example, Destination and Genmask are both 0.0.0.0. A gateway route to a narrower prefix has different values.

Balancing a Wire: Route Splitting by Range

Destination ranges can be directed through different paths. That divides address space; it does not guarantee an even traffic load or select servers by their current utilization. The following historical table illustrates prefix selection only, not a complete load-balancing configuration.

Its physical topology and return paths are not specified, so do not use this overlapping on-link example as a deployment recipe.

In this example, /25 takes precedence over /24 for destinations matching both. Listing order does not decide the result.

The same network address can appear in prefixes of different lengths. A /25 and /24 beginning at the same address are distinct, overlapping routes. A /0 covers all IPv4 destinations, while /32 covers one.

Here is a basic example of route splitting (branching logic):

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.10.0 0.0.0.0 255.255.255.128 U 0 0 0 enp2s0

The /24 spans 192.168.10.0 through 192.168.10.255: 256 addresses. The more specific /25 spans .0 through .127. These are address ranges, not counts of usable hosts.

The table assigns overlapping on-link ranges to two interfaces. That alone does not establish two independent LANs, working neighbor discovery, or a usable return path. A practical design needs those details checked separately.

For the displayed prefixes, .0 through .127 select enp2s0 via /25; .128 through .255 select eth0 via /24. This is the calculated route selection, not evidence that either physical path works.

Loopback and Localhost

The following is a historical local-table excerpt. Exact entries vary with kernel and address configuration; inspect ip -4 route show table local on the system being discussed.

local 127.0.0.0 dev lo  proto kernel  scope host  src 127.0.0.1
local 127.0.0.0/8 dev lo  proto kernel  scope host  src 127.0.0.1
local 127.0.0.1 dev lo  proto kernel  scope host  src 127.0.0.1
broadcast 127.255.255.255 dev lo  proto kernel  scope link  src 127.0.0.1

If we place those route instructions in a table, we can more easily digest what is going on.

route type destination interface device who installed route? scope source
local 127.0.0.0 loopback adapter the kernel local device 127.0.0.1
local 127.0.0.0/8 loopback adapter the kernel local device 127.0.0.1
local 127.0.0.1 loopback adapter the kernel local device 127.0.0.1
broadcast 127.255.255.255 loopback adapter the kernel local network 127.0.0.1

The local type means local delivery. dev lo names the loopback interface, proto kernel records who installed the route, and scope host limits its scope to this host. src 127.0.0.1 is a preferred source for locally originated traffic using the route; it does not rewrite every packet’s source address or perform NAT. The destination remains the prefix shown in that row.

The first two displayed rows both have scope host. Their difference is the destination prefix: a single address versus 127.0.0.0/8. The broadcast row has scope link. host, link, and global describe scope; global scope is not reserved for router devices. Multiple entries may reflect address-management behavior, so this excerpt is not a promise that a modern installation will show the same rows.