Learning Question
How does a host decide whether to send directly or through a gateway?
A host performs a routing-table lookup for the destination IP address. In the common simple case, the host checks whether the destination matches a connected route. If it does, the host sends directly to the destination’s link-layer address. If it does not, the host sends to a gateway’s link-layer address while keeping the final destination IP unchanged.
Same Subnet Case
Suppose the host has:
host IP: 192.168.1.10/24
gateway: 192.168.1.1
destination: 192.168.1.20The destination matches the connected route:
192.168.1.0/24 -> local interfaceThe host treats 192.168.1.20 as on-link. In IPv4, it uses ARP to ask for the destination’s MAC address:
Who has 192.168.1.20?Then it sends a local frame to that destination MAC address.
Remote Destination Case
Now suppose the destination is:
destination: 192.168.2.20That destination does not match the connected 192.168.1.0/24 route. The host uses another route, often the default route:
0.0.0.0/0 -> gateway 192.168.1.1The final destination IP remains 192.168.2.20, but the local frame is sent to the gateway’s MAC address.
IP packet:
destination IP = 192.168.2.20
local frame:
destination MAC = gateway's MACARP asks for the gateway’s MAC address, not the remote server’s MAC address.
What the Gateway Does
A gateway is the local Layer 3 device that can forward packets toward other networks. It must be reachable on the host’s local link because the host needs to deliver the first frame to it.
The gateway reads the destination IP, performs its own routing decision, and forwards the packet onward. It is not automatically the final server, the application process, or a load balancer. It is the next local routing hop.
Core Mental Model
The host chooses a next hop from its routing table.
local destination
-> resolve destination MAC
-> send frame directly to destination
remote destination
-> resolve gateway MAC
-> send frame to gateway
-> gateway routes packet onwardARP finds the local link-layer address for the next hop. Routing decides which next hop should be used.