Question

An entry in an IP forwarding table specifies both an interface and a gateway. Why is the gateway needed? No matter what, once you've picked the right forwarding entry to use to forward your packet, you're going to send your packet out the interface that forwarding entry specifies reagrdless of what value is in its gateway field.

Example

In this example, assume all netmasks are 255.255.255.0 for the simple, common case.

My IP address is 104.4.10.2, and I rely on the machine with IP address 104.4.10.1 to handle traffic I want to send to 104.4.40.X. The interface that connects me to 104.4.10.1 is named "eth1". My forwarding table will have this entry:

Destination     Netmask           Interface     Gateway  
===========     =============     =========     =======
104.4.40.0      255.255.255.0     eth1          104.4.10.1

If I want to send a packet to, say, 104.4.40.5, I'll bitwise and that IP address with the above forwarding entry's netmask of 255.255.255.0, get 104.4.40.0 as a result, see that this forwarding entry matches, and send the packet out eth1. I never even used the fact that there is a gateway of 104.4.10.1 as part of this forwarding entry.

So, I want to ask... Why is there a gateway field in a forwarding table entry?

Was it helpful?

Solution

For a local network route, the Gateway column (sometimes called Next Hop) might be blank or might contain the IP address of the interface on that network segment.

For a remote network route, the Gateway (Next Hop) column is the IP address of a local router located between the node and the remote network.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top