Default gateway
A default gateway is the next-hop router a device uses for a destination when its routing rules select a default route. A more-specific matching route can send traffic somewhere else.
Gateway and default route
The gateway is a next-hop device; the default route is a routing-table entry. A default IPv4 route normally uses prefix 0.0.0.0/0, and an IPv6 default route uses ::/0. A default route can point through a next-hop address or be expressed differently on particular link types.
Hosts can learn a gateway through mechanisms such as DHCP configuration, IPv6 Router Advertisements or an administrator's configuration. The last address octet has no special meaning: a gateway does not have to end in .1 or .254.
A packet leaving a subnet
A host is configured as 192.0.2.20/24 with default gateway 192.0.2.1. It wants to contact 198.51.100.8.
- A route lookup finds no more-specific route for
198.51.100.8and selects the default route. - On the local Ethernet network, the host resolves the gateway's link-layer address, using ARP for IPv4.
- It sends a frame to the gateway. The IP destination remains
198.51.100.8. - The gateway performs its own forwarding lookup. It is only the next step, not a guarantee of end-to-end delivery.
For another host inside 192.0.2.0/24, a directly connected route normally wins, so traffic does not first pass through the default gateway.
Inspect a host's decision
These Linux commands only display configuration and lookup results:
ip -4 route show default
ip -6 route show default
ip -4 route get 198.51.100.8
A default route might look like:
default via 192.0.2.1 dev eth0
If policy routing is configured, inspect the routing rules as well as the main table. Multiple interfaces can have different candidate defaults; the actual selected route is what matters for a particular packet.
Common confusions
A DNS resolver translates names; a gateway forwards traffic. They can share an address on a home router but perform different jobs. A host without a default gateway can still communicate over routes it already has, including directly connected networks. Conversely, a configured gateway does not prove that it is reachable or that it can reach the requested destination.