Linux-4.查看网卡信息

1.查看有几张网卡,也能看出网卡控制器的制造商信息
lspci | grep -i -E --color 'network|ethernet'

【实例】
root@demohost:~# lspci |grep -i eth
02:00.0 Ethernet controller: Broadcom Corporation NetXtreme II BCM5716 Gigabit Ethernet (rev 20)
02:00.1 Ethernet controller: Broadcom Corporation NetXtreme II BCM5716 Gigabit Ethernet (rev 20)
04:00.0 Ethernet controller: Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet (rev 20)
04:00.1 Ethernet controller: Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet (rev 20)
2张网卡

root@Yuanji-Debian-171:~# lspci |grep -i eth
02:00.0 Ethernet controller: Broadcom Corporation NetXtreme II BCM5716 Gigabit Ethernet (rev 20)
02:00.1 Ethernet controller: Broadcom Corporation NetXtreme II BCM5716 Gigabit Ethernet (rev 20)
1张网卡

2.可以使用lshw,
(系统没有自带,需要安装Debian:apt-get install lshw。 Centos: yum install lshw)
lshw -class network

【实例】
root@Yuanji-Debian-171:~# lshw -class network
  *-network:0             
       description: Ethernet interface
       product: NetXtreme II BCM5716 Gigabit Ethernet
       vendor: Broadcom Corporation
       physical id: 0
       bus info: pci@0000:02:00.0
       logical name: eth0
       version: 20
       serial: 78:2b:cb:58:74:5f
       size: 1GB/s
       capacity: 1GB/s
       width: 64 bits
       clock: 33MHz
       capabilities: pm vpd msi msix pciexpress bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=bnx2 driverversion=2.0.2 duplex=full firmware=5.2.3 NCSI 2.0.11 ip=192.168.4.171 latency=0 link=yes multicast=yes port=twisted pair speed=1GB/s
       resources: irq:16 memory:da000000-dbffffff
  *-network:1 DISABLED
       description: Ethernet interface
       product: NetXtreme II BCM5716 Gigabit Ethernet
       vendor: Broadcom Corporation
       physical id: 0.1
       bus info: pci@0000:02:00.1
       logical name: eth1
       version: 20
       serial: 78:2b:cb:58:74:60
       capacity: 1GB/s
       width: 64 bits
       clock: 33MHz
       capabilities: pm vpd msi msix pciexpress bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=bnx2 driverversion=2.0.2 duplex=half firmware=5.2.3 NCSI 2.0.11 latency=0 link=no multicast=yes port=twisted pair
       resources: irq:17 memory:dc000000-ddffffff
       
root@demohost:~# lshw -class network
  *-network:0             
       description: Ethernet interface
       product: NetXtreme II BCM5709 Gigabit Ethernet
       vendor: Broadcom Corporation
       physical id: 0
       bus info: pci@0000:04:00.0
       logical name: eth0
       version: 20
       serial: 00:10:18:b3:75:ec
       size: 1GB/s
       capacity: 1GB/s
       width: 64 bits
       clock: 33MHz
       capabilities: pm vpd msi msix pciexpress bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=bnx2 driverversion=2.0.2 duplex=full firmware=5.2.3 ip=192.168.4.178 latency=0 link=yes multicast=yes port=twisted pair speed=1GB/s
       resources: irq:16 memory:d6000000-d7ffffff
  *-network:1 DISABLED
       description: Ethernet interface
       product: NetXtreme II BCM5709 Gigabit Ethernet
       vendor: Broadcom Corporation
       physical id: 0.1
       bus info: pci@0000:04:00.1
       logical name: eth1
       version: 20
       serial: 00:10:18:b3:75:ee
       capacity: 1GB/s
       width: 64 bits
       clock: 33MHz
       capabilities: pm vpd msi msix pciexpress bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=bnx2 driverversion=2.0.2 duplex=half firmware=5.2.3 latency=0 link=no multicast=yes port=twisted pair
       resources: irq:17 memory:d8000000-d9ffffff
  *-network:0 DISABLED
       description: Ethernet interface
       product: NetXtreme II BCM5716 Gigabit Ethernet
       vendor: Broadcom Corporation
       physical id: 0
       bus info: pci@0000:02:00.0
       logical name: eth2
       version: 20
       serial: 78:2b:cb:58:76:7d
       capacity: 1GB/s
       width: 64 bits
       clock: 33MHz
       capabilities: pm vpd msi msix pciexpress bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=bnx2 driverversion=2.0.2 duplex=half firmware=5.2.3 NCSI 2.0.11 latency=0 link=no multicast=yes port=twisted pair
       resources: irq:16 memory:da000000-dbffffff
  *-network:1 DISABLED
       description: Ethernet interface
       product: NetXtreme II BCM5716 Gigabit Ethernet
       vendor: Broadcom Corporation
       physical id: 0.1
       bus info: pci@0000:02:00.1
       logical name: eth3
       version: 20
       serial: 78:2b:cb:58:76:7e
       capacity: 1GB/s
       width: 64 bits
       clock: 33MHz
       capabilities: pm vpd msi msix pciexpress bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
       configuration: autonegotiation=on broadcast=yes driver=bnx2 driverversion=2.0.2 duplex=half firmware=5.2.3 NCSI 2.0.11 latency=0 link=no multicast=yes port=twisted pair
       resources: irq:17 memory:dc000000-ddffffff


【个人常用】
-html           output hardware tree as HTML
-xml            output hardware tree as XML

lshw -html > /home/hwinfo.html
lshw -xml > /home/info.xml


【实例】

使用脚本,每天凌晨自动执行lshw -xml > /home/info+`date +%Y%m%d-%H%M%S`.xml

1>备份最原始的xml 作为资产管理

2>脚本对比当天和昨天的  XXX.xml   
3>如果有不同,将信息传回到公司,资产日志更新



3.查看非常详细的信息
lspci -vvv  # 3个小写的v
【实例】
root@Yuanji-Debian-171:~# lspci -vvv | grep -i -E '(net|eth)' -A 50
02:00.0 Ethernet controller: Broadcom Corporation NetXtreme II BCM5716 Gigabit Ethernet (rev 20)
        Subsystem: Dell Device 02a3
        Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+
        Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
        Latency: 0, Cache Line Size: 64 bytes
        Interrupt: pin A routed to IRQ 16
        Region 0: Memory at da000000 (64-bit, non-prefetchable) [size=32M]
        Capabilities: [48] Power Management version 3
                ---下面内容忽略,内容太长
                Kernel driver in use: bnx2  #驱动
--
02:00.1 Ethernet controller: Broadcom Corporation NetXtreme II BCM5716 Gigabit Ethernet (rev 20)
        Subsystem: Dell Device 02a3
        Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
        Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
        Latency: 0, Cache Line Size: 64 bytes
        Interrupt: pin B routed to IRQ 17
        Region 0: Memory at dc000000 (64-bit, non-prefetchable) [size=32M]
        Capabilities: [48] Power Management version 3
                ---下面内容忽略,内容太长
                Kernel driver in use: bnx2  #驱动

4.查看网卡当前状态
mii-tool  【通常用于 机房上架后网卡连接的检查】 ,网线是否连接,以及当前传送速度(1000baseT-FD)
【实例】
root@demohost:~# mii-tool  
eth0: negotiated 1000baseT-FD flow-control, link ok
SIOCGMIIPHY on 'eth1' failed: Resource temporarily unavailable
SIOCGMIIPHY on 'eth2' failed: Resource temporarily unavailable
SIOCGMIIPHY on 'eth3' failed: Resource temporarily unavailable

5.查看网卡驱动
ethtool

root@demohost:~# ethtool -i eth0
driver: bnx2
version: 2.0.2
firmware-version: 5.2.3
bus-info: 0000:04:00.0
root@demohost:~# ethtool -i eth2
driver: bnx2
version: 2.0.2
firmware-version: 5.2.3 NCSI 2.0.11
bus-info: 0000:02:00.0

6.从开机信息中查看网卡
# dmesg | grep -i eth
【实例】
root@demohost:/var/log# dmesg | grep -i --color eth
[    1.162042] Broadcom NetXtreme II Gigabit Ethernet Driver bnx2 v2.0.2 (Aug 21, 2009)
[    1.164195] eth0: Broadcom NetXtreme II BCM5709 1000Base-T (C0) PCI Express found at mem d6000000, IRQ 16, node addr 00:10:18:b3:75:ec
[    1.166331] eth1: Broadcom NetXtreme II BCM5709 1000Base-T (C0) PCI Express found at mem d8000000, IRQ 17, node addr 00:10:18:b3:75:ee
[    1.168236] eth2: Broadcom NetXtreme II BCM5716 1000Base-T (C0) PCI Express found at mem da000000, IRQ 16, node addr 78:2b:cb:58:76:7d
[    1.170235] eth3: Broadcom NetXtreme II BCM5716 1000Base-T (C0) PCI Express found at mem dc000000, IRQ 17, node addr 78:2b:cb:58:76:7e
[   12.021967] ACPI Error (psparse-0537): Method parse/execution failed [\_SB_.PMI0._GHL] (Node ffff88023fc2bd40), AE_NOT_EXIST
[   12.021981] ACPI Error (psparse-0537): Method parse/execution failed [\_SB_.PMI0._PMC] (Node ffff88023fc2bcc0), AE_NOT_EXIST
[   41.295829] bnx2: eth0: using MSIX
[   41.296444] ADDRCONF(NETDEV_UP): eth0: link is not ready
[   44.413942] bnx2: eth0 NIC Copper Link is Up, 1000 Mbps full duplex
[   44.414627] ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready


===========================
mii-tool,ethtool 详细说明
以及/proc/net/dev
/proc/interrupts | grep ethX
虚拟网卡
网卡参数的修改
网卡流量的查看
会在后面后续文章说到

以上是个人点点总结和理解,水平不高,文笔水平很烂,请各位大大见谅。
可以一起交流学习。

  我的QQ:610851588
  可以加入我建的群(现在群人很少,希望慢慢多起来)
  Linux  群:183932302
  Python ,shell 交流群:469094734