Configuration and routing
Read the routing table
Read destination prefixes, next hops, and interfaces, then identify the most specific matching route.
A host uses its routing table to choose where an IP packet goes next. A route includes a destination prefix and an outgoing interface, and may include a next-hop router.
The most specific matching prefix wins. A route for 192.0.2.0/24 is preferred over a default route for 0.0.0.0/0 when both match the destination.
Read the table
Inspect routes on Linux or macOS with:
ip route
netstat -rn
A typical home machine shows two important rows:
default via 192.168.1.1 dev wlan0
192.168.1.0/24 dev wlan0 scope link
The 192.168.1.0/24 line is an on-link route. Traffic to any address in that prefix goes directly out wlan0 after neighbor discovery. The default via 192.168.1.1 line is the fallback for everything else. Packets go to the router first.
An on-link route sends directly to the destination after neighbor discovery. A gateway route sends the frame to a router. The default route is only the fallback when no more specific route matches.
Ask the kernel to choose
Reading the table is useful, but ip route get shows what the kernel would actually pick for one destination:
Inspect the routes your machine will really use:
ip route
ip route get 1.1.1.1
ip route get 192.168.1.1
The first command shows the table. The next commands ask the kernel to choose a path for one destination. Record the selected interface, gateway, and source address. If your system uses route -n or netstat -rn instead, find the same four facts rather than memorizing one operating-system command.
For 1.1.1.1 you should see a via gateway and a src address on your LAN. For 192.168.1.1 on the same subnet, you should see direct delivery with no gateway. If those answers disagree with what you expect, the routing table is where the mismatch lives.
My advice is to run ip route get before you change routes. It tells you what the kernel already decided, and it saves you from adding a route that duplicates or conflicts with an existing one.
Lesson completed