A routing table dump shows possible routes. ip route get asks the kernel to
resolve one destination with a specific source, mark, interface, or protocol
context.
The command returns the decision as the kernel sees it and does not transmit a packet 1.
Resolve one destination
ip route get 203.0.113.10Typical fields include:
203.0.113.10 via 192.0.2.1 dev eth0 src 192.0.2.20 uid 1000
cache| Field | Meaning |
|---|---|
via |
next-hop gateway |
dev |
selected output interface |
src |
preferred local source address |
uid |
user identity included in the lookup |
table |
selected routing table when printed |
The documentation distinguishes get, which resolves a route, from show,
which lists entries 1.
Include the source when it matters
Multi-homed systems may choose different tables or gateways by source address:
ip route get 203.0.113.10 from 192.0.2.20
ip route get 203.0.113.10 from 198.51.100.20The source must exist in the namespace unless the lookup context explicitly models forwarded traffic. A VPN, VRF, container, or policy rule can change the answer.
For transport-aware policy:
ip route get 203.0.113.10 \
ipproto tcp sport 40000 dport 443Ports affect the result only when policy rules or route selection use them.
Read policy rules in priority order
ip rule show
ip route show table main
ip route show table localRules select a routing table or another action. Lower numeric priorities are
processed first, so a correct route in main may never be consulted
2.
Firewall marks can participate in policy routing:
ip route get 203.0.113.10 mark 0x2Use the mark value from the actual packet path. Inventing one answers a different question.
A loopback lab
This query is read-only and stays local:
ip route get 127.0.0.1
ip -json route get 127.0.0.1The text form normally names the local route, lo, and source 127.0.0.1.
The JSON form is easier to parse, but consumers should still select named fields
instead of relying on display order.
Run inside the relevant namespace
ip route get sees only the namespace where it runs. A host result does not
describe a container’s routing table.
ip netns list
sudo ip netns exec example ip route get 203.0.113.10Caution: Listing namespaces and routes is read-only.
ip route add,replace,del, and especiallyflushchange connectivity immediately. Capture the current rules and all relevant tables before an approved change.
Save the lookup arguments and result together. A route without its destination, source, mark, namespace, and timestamp is incomplete incident evidence.