What exactly does gateway in a route refer to? I know what a default gateway is- it's the route of last resort. But used in context of a host route (with destination specified), what is a gateway and why is it important?

migrated from stackoverflow.com Feb 15 '10 at 7:34

This question came from our site for professional and enthusiast programmers.


Quoting this excellent handbook,

A “route” is a defined pair of addresses: a “destination” and a “gateway”. The pair indicates that if you are trying to get to this destination, communicate through this gateway.

So, a gateway is any router (or routing host) through which packets pass (are sent) when trying to reach a given set of destinations.

  • So then would the defined IP tables on the gateway determine what happens to the packet from there? – Jonathan Neufeld Sep 5 '18 at 19:13

The gateway is the next hop in both default routing and host routing.

Since almost every interface has an address, it knows about its locally connected network and so the host needs no routing info as all stations on the same network are addressable.

Typically, only a default gateway is needed next, once the packet reaches the default gateway routing becomes someone else's problem.

But imagine a network with multiple exit points. Some may be faster than others. Some may be more expensive. Some may have administrative restrictions on traffic.

So, to route to a specific remote network or a specific remote host, the only thing the originating station needs to know is "where do I send the packet so it becomes someone else's problem". If there is more than one multihomed system ("router") then a decision must be made, for each destination host or network, which exact host on the local network will handle the packet after it leaves the originating interface.

Once again, a one-hop route is all that is needed. As you can see, the originating endpoint is not really in control of routing, except for the first hop. That's part of the magic of IP and the reason it has displaced all other networking technologies.


It's the machine that receives packets that are being sent to a specific range of addresses.


Each router has three values Address, Mask and Gateway. Whenever an IP packet arrives at a router, its IP address is masked (using bit-wise AND) with a Router Mask and compared to a Router Address. If the the Masked IP address is same as Router Address it is sent to a corresponding gateway. Just keep in mind this is a simplification of the process, in reality it is a wee bit more complex.

In layman's terms each packet knows where he is headed (IP address) but doesn't know how to get there, so he asks each router for directions (masking IP address and comparing to router address). Of course routers probably don't know where exactly he should go, but they can give directions as to where they might find someone who can (gateway). In case they haven't got any clue where that place is, they just send you to a default gateway.


But used in context of a host route (with destination specified), what is a gateway and why is it important?

When you want to send a packet to someone not on the immediate network, you can't just put it on the wire, because they won't see it.

What instead happens is that the system looks at its routing tables, determines the appropriate gateway, and basically says to it "Hey, could you forward this to where it's supposed to go?"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy