Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers 3

up vote 9 down vote accepted

Use ip route get <ip>.

share|improve this answer
    
Thanks. That is what I was looking for. –  sandoz Oct 10 '10 at 16:51
1  
And to get only the interface: ip -o route get $ipaddress | perl -nle 'if(/dev\s+(\S+)/) {print $1}' –  mivk Jul 6 at 13:32
add comment

what about route -C

share|improve this answer
add comment

I use netstat -Wcatnp . You should try this command.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.