LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

ip-route-get

performs a route lookup and displays exactly which route the kernel would use

TLDR

Print route to destination
$ ip route get [1.1.1.1]
copy
Print route from a specific source
$ ip route get [destination] from [source]
copy
Print route for packets arriving on a specific interface
$ ip route get [destination] iif [eth0]
copy
Print route forcing output through specific interface
$ ip route get [destination] oif [eth0]
copy
Print route with Type of Service
$ ip route get [destination] tos [0x10]
copy
Print route using VRF instance
$ ip route get [destination] vrf [myvrf]
copy
Print route for a packet with a firewall mark (policy routing)
$ ip route get [destination] mark [0x1]
copy
Show the matching FIB entry instead of the resolved route
$ ip route get fibmatch [destination]
copy
Look up a route for a specific protocol and port
$ ip route get [destination] ipproto [tcp] dport [443]
copy
Look up an IPv6 route
$ ip -6 route get [2606:4700:4700::1111]
copy

SYNOPSIS

ip route get [fibmatch] ADDRESS [from ADDRESS] [iif DEV] [oif DEV] [mark MARK] [tos TOS] [vrf NAME] [ipproto PROTOCOL] [sport NUMBER] [dport NUMBER] [connected]

DESCRIPTION

ip route get performs a route lookup and displays exactly which route the kernel would use for a given destination. This shows the complete route entry including gateway, interface, source address, and any other attributes.Unlike ip route list, which shows stored routes, ip route get queries the kernel's routing decision for a specific packet, accounting for policy routing rules and route selection algorithms. It is equivalent to sending a packet along this path, but no packets are actually sent. Without iif, the kernel resolves a route for locally generated output; with iif, it pretends a packet arrived on that interface and looks for a forwarding path.

PARAMETERS

fibmatch

Return the full FIB lookup matched route instead of the resolved destination entry
to ADDRESS
Destination address (the to keyword is optional)
from SOURCE
Source address for route lookup
iif DEVICE
Input interface (for forwarded packets)
oif DEVICE
Force output interface
tos, dsfield TOS
Type of Service value
vrf NAME
VRF instance name
mark MARK
Firewall mark (fwmark) value
ipproto PROTOCOL
IP protocol as seen by the route lookup
sport NUMBER, dport NUMBER
Source and destination port as seen by the route lookup
connected
If no from is given, redo the lookup with the source set to the preferred address from the first lookup

INSTALL

sudo apt install iproute2
copy
sudo pacman -S iproute2
copy
sudo apk add iproute2-minimal
copy
sudo zypper install iproute2
copy
brew install iproute2
copy
nix profile install nixpkgs#iproute2
copy

CAVEATS

The output reflects the current routing state, which may change dynamically. VRF lookups require the VRF to be configured. Mark-based lookups require matching policy rules. Using iif requires IP forwarding to be enabled, otherwise the lookup may fail.

HISTORY

ip route get is part of iproute2 and provides insight into the kernel's actual routing decisions, which can differ from the stored route table due to policy rules and route metrics.

SEE ALSO

ip(8), ip-route(8), ip-route-list(8), ip-rule(8)

RESOURCES

Copied to clipboard
Kai