Frequently Asked Question
What is a default gateway and how do I add one?
Your machine has a routing table telling it which interface to use for which
destination. Anything on a directly connected subnet (192.168.1.0/24 if your
address is 192.168.1.42/24) is reached by sending an ARP request and putting
the packet on the wire. Anything else, including the entire internet, has to
be handed to a gateway: a router that knows how to forward your packet onwards.
The default gateway is the catch-all entry used when no more specific route
matches.
ip route shows it as a line beginning default via 192.168.1.1 dev eth0. To
add one by hand (rare; normally DHCP supplies it), use sudo ip route add default via 192.168.1.1. If ip route shows no default route, you can talk to
your local network but not the internet, one of the most common symptoms when
DHCP fails or a static configuration is incomplete. ip route get 8.8.8.8
confirms which gateway and interface a packet would actually use.