Routes, Gateways and NAT
Quick answer
Routing chooses a path for a destination; a gateway is a possible next hop. NAT translates addresses or ports and is not the same as routing.
Prepare the practice environment
Run python3 lab-fixtures/networking/setup.py from the extracted package root as an ordinary user. Enter the printed private path and check pwd. Use a fresh fixture, Bash with LC_ALL=C and set -o pipefail. Python 3 is required for the fixed local socket helper. Use only loopback or synthetic data; never apply sample configuration. Manual examples require an authorized disposable VM.
How it works
Within the selected routing table the most specific matching prefix normally wins. Policy routing may select tables first; metrics and multipath matter among applicable routes. A default route /0 is a fallback, not proof of Internet access. NAT may change source or destination addresses and ports at a forwarding device; it is not a firewall policy by itself. ip route get asks the kernel for its route decision without sending a probe packet. Use documentation addresses only in diagrams.
Suppose the selected table has 192.0.2.0/24 and 192.0.2.64/26 routes as well as a default route. A destination of 192.0.2.70 matches both explicit prefixes, so the /26 wins under ordinary longest-prefix selection. A route lookup tells you the proposed path; it does not establish that the gateway answers, forwarding works, or a firewall allows traffic. Treat this example as a fictional table.
Try the examples
ip route get 127.0.0.1 | awk 'NR==1 {print $1,$2,$3,$4}'The local route uses lo, not an external gateway.
Expected stdout:
local 127.0.0.1 dev loThe table is illustrative. For 198.51.100.9, the specific /24 matches.
Expected stdout:
default via 192.0.2.1 dev lab0192.0.2.0/24 dev lab0198.51.100.0/24 via 192.0.2.2 dev lab0Extracts the gateway only from this fixed-format fixture.
Expected stdout:
192.0.2.1Common mistakes
Do not change routes or enable forwarding on a real machine for practice; a bad route can disconnect remote administration.
Practice
For fictional destinations 192.0.2.9, 198.51.100.9 and 203.0.113.9 select the matching route and explain why.
Related references
Study: ip. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Routes, gateways and NAT — Knowledge Check
Apply network concepts to loopback, synthetic fixtures and VM-only scenarios.
What normally wins within a selected table?
Default route prefix?
Does ip route get send a probe?
What is NAT?