Sunday, August 5, 2012

How to find which are the NICs have physical link UP ?

Scenario -1: Assume you have 4 network Card in you Linux box. 2 out of 4 network card are connected with switch but you do not know which of them ?

Scenario -2: Network team says that they have connected a cable in one of 4 NICs of Linux box. how to find in which NIC?

  • Bring up all interfaces
     for i in $(ifconfig -a|grep ^eth|cut -d " " -f1) ; do ifup $i ;done
     
  • Take note of MAC addresses of all NIC
    grep "" /sys/class/net/eth*/address 
     
  • Check Link status. Use any of below.(use any one of below)
    grep "" /sys/class/net/eth*/carrier 2>/dev/null  #Status 1 is means linked
    grep "" /sys/class/net/eth*/operstate 2>/dev/null
    for i in $(ifconfig -a|grep ^eth|cut -d " " -f1) ; do 
        echo $i;ethtool $i| grep Link;done| paste - -
    mii-tool 2>/dev/null
    ip link show |grep LOWER_UP