21

My "Dedicated Server" should have two NICs installed but I can only find one.

My Question: What other commands and methods are available to test how many network cards are installed on my server

lspci | grep Ethernet

Are there any other commands / methods available?

jscott
  • 24,484
  • 8
  • 79
  • 100
jens
  • 255
  • 1
  • 3
  • 6
  • Do you have physical access to the host? Can you confirm that any expansion cards are properly seated? Are all NIC's from the same manufacturer? – Tok Feb 24 '11 at 16:22
  • Hello Tok. Thanks for your answer.No the NIC's are not from the same manufacturer (one should be from intel and the other from realtek). =>Your question sounds interesting. What could be the effect/result if the cards are from different manufacturers? And I do not have physical access to the server and do not know if they are correctly installed. thanks. jens. – jens Feb 24 '11 at 18:01

8 Answers8

20
find /sys/class/net -type l -not -lname '*virtual*' -printf '%f\n'

Shows just interfaces that relate to a physical NIC.

Tried to find a type option to ip link show that would display non-logical, but alas:

ip link help 2>&1 | grep -A10 'TYPE :='
TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | macvtap |
          bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan |
          gre | gretap | ip6gre | ip6gretap | vti | nlmon |
          bond_slave | ipvlan | geneve | bridge_slave | vrf }

It seems to be the one thing that ip link show cannot do. At least not without resorting to a script that first lists each of the above and then does grep -v against a final run without type specified.

banankage
  • 301
  • 2
  • 3
  • This definitely seems like something `ip link` should be able to handle. If using a lot of virtual interfaces (say for bridging or vlan) and especially if these virtual interfaces have been renamed. – Centimane Dec 05 '17 at 17:37
19

You can use lshw to see all devices on a machine. To view just the network devices enter:

lshw -class network
pyasi
  • 520
  • 2
  • 6
  • 6
    lshw is not part of a default Debian setup. – Jean-Marc Liotier Sep 13 '11 at 23:56
  • 1
    I find this a bit too much, I'll rather just: ip link show – Matías Nov 03 '14 at 15:24
  • 1
    This also display the bridge interfaces, which are not physicals. – Xorax Sep 29 '17 at 19:20
  • This is definitely not a widely available program, and especially not so on machines where I'm trying to figure out basic things like how many physical network devices there are. On my local workstation, where I can install software like lshw, I already know things like what network cards are installed. – Todd Walton Aug 26 '21 at 19:46
  • @pyasi, I think this reply does not answer the question, because the `network` class will contain all virtual networks too, e.g. VLANs, bonding, ... – andras.tim Mar 23 '22 at 10:19
16

ip link show will list everything that looks like a network interface.

LawrenceC
  • 1,202
  • 7
  • 14
  • ...which makes it not suitable for the question asked. The asker said he or she wanted a list that didn't include everything, but rather just a subset. – Todd Walton Aug 26 '21 at 19:47
11

For Ethernet:

ls -d /sys/class/net/eth* | wc -l
ooshro
  • 11,134
  • 1
  • 32
  • 31
  • 1
    This does not work in general because ethernet device names do not have to start with eth. Many (all?) major linux distros are now using "predictable ethernet interface names" with systemd, resulting in wired interface names like en0 or enp0s25, so looking for eth* will miss those. – rajb245 Jan 30 '18 at 15:44
  • 3
    Give this a try: `$ ls -l /sys/class/net/ | grep -v virtual`. It filters all virtual network interfaces out. Work on ubuntu running in a Virtual Box. – kwarnke May 15 '18 at 11:11
7

/proc/net/dev file has details on all interfaces. e.g.

$ cat /proc/net/dev
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
    lo:    3562      60    0    0    0     0          0         0     3562      60    0    0    0     0       0          0
 wlan0: 2491781197 2034240    0    0    0     0          0         0 261797069 1502752    0    0    0     0       0          0
  eth0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0

As you can see, many columns and details are not very easy to read when you cat the file so I would suggest to use ifconfig command which reads that file and formats output nicely.

To list all interfaces use

/sbin/ifconfig -a

that will show you the unconfigured/down network interfaces as well as configured and active ones, as read from /proc/net/dev

Hrvoje Špoljar
  • 5,245
  • 26
  • 42
6

ls -d /sys/class/net/*/device | cut -d/ -f5 will list only real NICs, leaving out bonds, loopback devices and so on.

As a bonus, ls -l /sys/class/net/*/device/driver/module | cut -d/ -f5,13 | sed 's?/? -> ?' will also show the driver bound to it.

Example on a hardware firewall from a major vendor out there:

# ls -l /sys/class/net/*/device/driver/module | cut -d/ -f5,13 | sed 's?/? -> ?'
Mgmt -> igb
Sync -> igb
eth2-01 -> igb
eth2-02 -> igb
eth2-03 -> igb
eth2-04 -> igb
eth2-05 -> igb
eth2-06 -> igb
eth2-07 -> igb
eth2-08 -> igb
eth3-01 -> ixgbe
eth3-02 -> ixgbe
Nicolas Melay
  • 615
  • 5
  • 12
1
modprobe -c |grep 'eth[0-9]'

shows the real device driver in use for each ethernet device

Paul S
  • 186
  • 4
0

This works great for me

lshw -class network -businfo
sysadmin1138
  • 133,124
  • 18
  • 176
  • 300
Sean
  • 1