Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Suppose I have multiple network cards connected to my PC, how can I know which card is used for communication. For example, if I use

ping 192.168.x.xxx

I would like to know which card (and which IP address) used for communication.

The command

netstat

will tell us about the active connections. I am not interested in active connections, but I would like to know which card will be used for next connection. That is, if we use ping which card (or IP address) will be used ?

share|improve this question
    
Which OS are you using? –  Flimzy Jun 30 '11 at 8:20
    
@Flimzy: Was there any misleading words in my question ? –  Muhammed Rauf K Jun 30 '11 at 8:41
    
Are you asking about my edit? Your title was too vague... "communication with multiple cards" could refer to many things, including routing, bridging, or bonding. –  Flimzy Jun 30 '11 at 8:44
    
Ohk. Thanks. I will take this in mind for next questions and answers –  Muhammed Rauf K Jun 30 '11 at 8:48

3 Answers 3

up vote 0 down vote accepted

Try route print; it'll show you the OS's table of networks and which network interface it'll use for each, or where there's multiple cards on the one network the weighting it'll use in distributing the traffic. I've only got one card in this machine so this isn't very interesting:

===========================================================================
Interface List
0x1 ........................... MS TCP Loopback interface
0x2 ...00 12 34 56 78 9a ...... Intel(R) 82566DM Gigabit Network Connection
===========================================================================
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0      123.45.67.1   123.45.67.137       10
        127.0.0.0        255.0.0.0        127.0.0.1       127.0.0.1       1
      234.254.0.0      255.255.0.0    123.45.67.137   123.45.67.137       20
      123.45.67.0    255.255.255.0    123.45.67.137   123.45.67.137       10
    123.45.67.137  255.255.255.255        127.0.0.1       127.0.0.1       10
   123.45.255.255  255.255.255.255    123.45.67.137   123.45.67.137       10
        224.0.0.0        240.0.0.0    123.45.67.137   123.45.67.137       10
  255.255.255.255  255.255.255.255    123.45.67.137   123.45.67.137       1
    Default Gateway:       123.45.67.1
===========================================================================
Persistent Routes:
  None

so e.g. from the second line traffic to 127.x.x.x will use the loopback interface but traffic to multicast and everything else will use the network card. I'm not sure how to read this programattically, though, sorry.

share|improve this answer

The card used is determined by the IP address configured on that card. It is worth noting that it is not generally valid to configure IP addresses on the same subnet to different physical interfaces. (Yes there are exceptions to this, but they are generally very specific, and unlikely to be useful to you at this level).

Which physical card is associated with which logical name within your operating system is a thornier issue. The easiest way to determine this is unplug all but one of the network cables and see which IP address you can still communicate on.

What operating system are you using, for certain OS types there are sometimes easier ways of determining which card has been unplugged - Windows, for example, provides visual feedback via the system tray icons.

share|improve this answer

netstat would tell you - the local address listed in netstat would be the ip address of the network card you are using

Lets take a snippet of my own netstat output on windows - i'm connected to my lan over 192.168.1.127, and a crossover lan connection over 10.0.0.2

 Proto  Local Address          Foreign Address        State
  TCP    10.0.0.2:56702         ARTEMIS:ms-wbt-server  ESTABLISHED
  TCP    127.0.0.1:19872        Athena:49172           ESTABLISHED
  TCP    192.168.1.127:2869     192.168.1.254:49565    TIME_WAIT
  TCP    192.168.1.127:56523    stackoverflow:http     ESTABLISHED

10.0.0.2 is the adaptor on the local crossover, connected to ARTEMIS, which is running a RDP server, 192.168.1.127 is talking to my router, which is 192.168.1.254, and stackoverflow. Note also that local connections on 127.0.0.1 are represented.

on linux you may need to use

netstat -n

i only have one port active in my linux box, but it'll look something like - for an ip address 192.168.1.127

   tcp        0     52 192.168.1.127:22        121.7.51.154:56383      ESTABLISHED
share|improve this answer

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.