How to see on Linux what network interface and source IP address is used for a route to a specific destination host?
25,702
Use ip route get <ip>
.
Related videos on Youtube
Author by
sandoz
Updated on September 17, 2022Comments
-
sandoz almost 2 years
If I have multiple network interfaces (here: 2) on a Linux machine (here: Debian Lenny). How do I see, over what network interface (NIC) a route to a specific destination host is going and what source IP address is used by default?
I have though of using
ping -I nic1 desthost.example.com ping -I nic2 desthost.example.com
too see if both ways are possible. (Here: Both ways are possible)
I looked up the routing table
ip route show
But it's quite complex, so I thought, there must by a small simple tool, to just tell me:
"To destination host desthost.example.com it takes interface nicX and source IP address 10.0.0.1"
What is the simplest way of getting this information?
(And I'd rather not use tcpdump and set the interfaces in promiscous mode.)
Thanks.
-
mivk almost 10 yearsAnd to get only the interface:
ip -o route get $ipaddress | perl -nle 'if(/dev\s+(\S+)/) {print $1}'
-
ShadowFlame over 9 yearsor
ip -o route get $ipaddress | awk '{ print $5 }'
-
madCode over 8 yearsroute is deprecated. use iproute2.
-
Per Lundberg about 4 yearsWhat is
nm-tool
and in what package is it provided? Something related to NetworkManager? -
Nasir almost 3 yearsip -6 route get 240b:c020:104:5422:bb27:2:1d:134 for example doest print anything. But its pingable
-
Admin about 2 yearsRecent Linuxes dropped
netstat
in favor ofss
. -
Admin about 2 yearsYes, it required NetworkManager (which is not installed universally).
-
Admin about 2 yearsPlease make the answer somewhat more complete (e.g. explain). If I try the command I just get a header.