如何在Linux中找出总的NIC卡和总的可用物理端口


1

我需要找出服务器上总共有多少个物理端口,正在使用中的端口以及有多少个空闲端口。您能帮忙找到它吗:

这是我从dmidecode输出中找到的:

    # dmidecode | egrep -i "PCI|Available|in use"
    PCI is supported
    ESCD support is available
    Designation: PCI-E Slot 1
    Type: x8 PCI Express
    Current Usage: In Use
    Designation: PCI-E Slot 2
    Type: x8 PCI Express
    Current Usage: Available
    Designation: PCI-E Slot 3
    Type: x4 PCI Express
    Current Usage: Available
    Designation: PCI-E Slot 4
    Type: x8 PCI Express
    Current Usage: In Use
    Designation: PCI-E Slot 5
    Type: x8 PCI Express
    Current Usage: In Use

    # dmidecode | grep -i "NIC"
    HP BIOS NIC PCI and MAC Information
    NIC 1: PCI device 04:00.0, MAC address 00:1E:0B:C0:F4:92
    NIC 2: PCI device 42:00.0, MAC address 00:1E:0B:C0:F4:90
    HP BIOS iSCSI NIC PCI and MAC Information
    NIC 1: PCI device 04:00.0, MAC address 00:1E:0B:C0:F4:93
    NIC 2: PCI device 42:00.0, MAC address 00:1E:0B:C0:F4:91

    [root@eir1 network-scripts]# cat ifcfg-eth[0123] | grep -i HWADDR
    HWADDR=00:1E:0B:C0:F4:92
    HWADDR=00:1E:0B:C0:F4:90
    HWADDR=00:26:55:e6:75:5c
    HWADDR=00:26:55:e6:75:5d

我如何从中得出结论,正在使用多少物理端口以及多少可用端口?请帮助

Answers:


1

您可以尝试/sbin/ifconfig -aip link show进一步尝试ethtool

后者显示了连接状态。


不过,这仅在驱动器已加载的情况下有效(例如,它将不会显示没有附带驱动程序的NIC)。
Hennes

@sebastianwagner ifconfignet-tools包现已弃用了一段时间。您应该切换为仅使用iproute2带有命令的软件包ip。@Hennes的问题是关于知道哪些端口正在使用和哪些可用。这些信息只有在加载了驱动程序后才能知道,所以我认为这是一个正确的答案。
Piernov

1

这是您需要做的。

首先找到所有NIC端口,每行是一个端口。

-bash-4.1# lspci | grep -i ethernet
03:00.0 Ethernet controller: Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet (rev 20)
03:00.1 Ethernet controller: Broadcom Corporation NetXtreme II BCM5709 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)
08:00.0 Ethernet controller: Solarflare Communications SFC9120 (rev 01)
08:00.1 Ethernet controller: Solarflare Communications SFC9120 (rev 01)
0b:00.0 Ethernet controller: Solarflare Communications SFC9020 [Solarstorm]
0b:00.1 Ethernet controller: Solarflare Communications SFC9020 [Solarstorm]
0e:00.0 Ethernet controller: Intel Corporation 82580 Gigabit Network Connection (rev 01)
0e:00.1 Ethernet controller: Intel Corporation 82580 Gigabit Network Connection (rev 01)
0e:00.2 Ethernet controller: Intel Corporation 82580 Gigabit Network Connection (rev 01)
0e:00.3 Ethernet controller: Intel Corporation 82580 Gigabit Network Connection (rev 01)
11:00.0 Ethernet controller: Solarflare Communications SFC9120 (rev 01)
11:00.1 Ethernet controller: Solarflare Communications SFC9120 (rev 01)

我如何知道哪个端口是哪个NIC接口?(例如,eth0)

-bash-4.1# ethtool -i eth0
driver: sfc
version: 4.1.2.1003b
firmware-version: 4.2.2.1003 rx1 tx1
bus-info: 0000:08:00.0
supports-statistics: yes
supports-test: yes
supports-eeprom-access: no
supports-register-dump: yes
supports-priv-flags: no

现在您可以看到bus-info: 0000:08:00.0比赛08:00.0 Ethernet controller: Solarflare Communications SFC9120 (rev 01)

所以eth0是Solarflare的港口之一,容易检查其是否在运行

ip link show eth0

现在,您将能够找到您拥有多少个NIC端口,每个卡上有多少个空闲端口。

谢谢


0

我不确定物理端口到底是什么意思。dmidecode可以列出连接器,

 # dmidecode --type 8 
 # dmidecode 2.12
 SMBIOS 2.5 present.

 Handle 0x0004, DMI type 8, 9 bytes
 Port Connector Information
    Internal Reference Designator:  
    Internal Connector Type: None
    External Reference Designator: EXTERNAL MONITOR PORT
    External Connector Type: DB-15 female
    Port Type: Other

    Handle 0x0005, DMI type 8, 9 bytes
    Port Connector Information
    Internal Reference Designator:  
    Internal Connector Type: None
    External Reference Designator: BUILT-IN LAN PORT
    External Connector Type: RJ-45
    Port Type: Network Port

    Handle 0x0006, DMI type 8, 9 bytes
    Port Connector Information
    Internal Reference Designator:  
    Internal Connector Type: None
    External Reference Designator: USB PORT
    External Connector Type: Access Bus (USB)
    Port Type: USB

    Handle 0x0007, DMI type 8, 9 bytes
    Port Connector Information
    Internal Reference Designator:  
    Internal Connector Type: None
    External Reference Designator: USB PORT
    External Connector Type: Access Bus (USB)
    Port Type: USB

    Handle 0x0008, DMI type 8, 9 bytes
    Port Connector Information
    Internal Reference Designator:  
    Internal Connector Type: None
    External Reference Designator: USB/eSATA PORT
    External Connector Type: Access Bus (USB)
    Port Type: USB

    Handle 0x0009, DMI type 8, 9 bytes
    Port Connector Information
    Internal Reference Designator:  
    Internal Connector Type: None
    External Reference Designator: HEADPHONE JACK
    External Connector Type: Mini Jack (headphones)
    Port Type: Other

    Handle 0x000A, DMI type 8, 9 bytes
    Port Connector Information
    Internal Reference Designator:  
    Internal Connector Type: None
    External Reference Designator: HDMI-CONNECTOR
    External Connector Type: Other
    Port Type: Video Port

    Handle 0x000B, DMI type 8, 9 bytes
    Port Connector Information
    Internal Reference Designator:  
    Internal Connector Type: None
    External Reference Designator: MICROPHONE JACK
    External Connector Type: Other
    Port Type: Other

或系统插槽

  # dmidecode --type 9
  # dmidecode 2.12                                                                                                                                                                                
  SMBIOS 2.5 present.                                                                                                                                                                             

  Handle 0x000C, DMI type 9, 13 bytes                                                                                                                                                             
  System Slot Information                                                                                                                                                                         
    Designation: SD CARD                                                                                                                                                                    
    Type: Other                                                                                                                                                                             
    Current Usage: In Use                                                                                                                                                                   
    Length: Other                                                                                                                                                                           
    Characteristics:                                                                                                                                                                        
            3.3 V is provided                                                                                                                                                               
            Hot-plug devices are supported                                                                                                                                                  

  Handle 0x000D, DMI type 9, 13 bytes                                                                                                                                                             
  System Slot Information                                                                                                                                                                         
    Designation: EXPRESS CARD                                                                                                                                                               
    Type: x1 PCI Express                                                                                                                                                                    
    Current Usage: In Use
    Length: Other
    ID: 1
    Characteristics:
            3.3 V is provided
            Hot-plug devices are supported

你还需要什么?您可以在dmidecode的sourceforge页面上找到所有相关代码


0

要将卡/端口与特定的接口名称相关联,以下命令也很方便。

/ sys / class / net中的链接具有总线号,该总线号可以将端口映射到接口名称。

root@xxx:~# ls -l /sys/class/net/
total 0
lrwxrwxrwx 1 root root    0 Aug  7 16:51 bond0 -> ../../devices/virtual/net/bond0
-rw-r--r-- 1 root root 4096 Aug  7 12:56 bonding_masters
lrwxrwxrwx 1 root root    0 Aug  7 16:51 eno1 -> ../../devices/pci0000:00/0000:00:01.1/0000:04:00.0/net/eno1
lrwxrwxrwx 1 root root    0 Aug  7 16:51 eno2 -> ../../devices/pci0000:00/0000:00:01.1/0000:04:00.1/net/eno2
lrwxrwxrwx 1 root root    0 Aug  7 16:51 eno3 -> ../../devices/pci0000:80/0000:80:01.0/0000:81:00.0/net/eno3
lrwxrwxrwx 1 root root    0 Aug  7 16:51 eno4 -> ../../devices/pci0000:80/0000:80:01.0/0000:81:00.1/net/eno4
lrwxrwxrwx 1 root root    0 Aug  7 16:51 enp6s0 -> ../../devices/pci0000:00/0000:00:02.0/0000:06:00.0/net/enp6s0
lrwxrwxrwx 1 root root    0 Aug  7 16:51 enp6s0d1 -> ../../devices/pci0000:00/0000:00:02.0/0000:06:00.0/net/enp6s0d1
lrwxrwxrwx 1 root root    0 Aug  7 16:51 enp8s0 -> ../../devices/pci0000:00/0000:00:03.0/0000:08:00.0/net/enp8s0
lrwxrwxrwx 1 root root    0 Aug  7 16:51 enp8s0d1 -> ../../devices/pci0000:00/0000:00:03.0/0000:08:00.0/net/enp8s0d1
lrwxrwxrwx 1 root root    0 Aug  7 16:51 enp9s0 -> ../../devices/pci0000:00/0000:00:03.2/0000:09:00.0/net/enp9s0
lrwxrwxrwx 1 root root    0 Aug  7 16:51 enp9s0d1 -> ../../devices/pci0000:00/0000:00:03.2/0000:09:00.0/net/enp9s0d1
lrwxrwxrwx 1 root root    0 Aug  7 16:51 lo -> ../../devices/virtual/net/lo
root@xxx:~# lspci -nn |grep Ether
04:00.0 Ethernet controller [0200]: Intel Corporation I350 Gigabit Network Connection [8086:1521] (rev 01)
04:00.1 Ethernet controller [0200]: Intel Corporation I350 Gigabit Network Connection [8086:1521] (rev 01)
06:00.0 Ethernet controller [0200]: Mellanox Technologies MT27500 Family [ConnectX-3] [15b3:1003]
08:00.0 Ethernet controller [0200]: Mellanox Technologies MT27500 Family [ConnectX-3] [15b3:1003]
09:00.0 Ethernet controller [0200]: Mellanox Technologies MT27500 Family [ConnectX-3] [15b3:1003]
81:00.0 Ethernet controller [0200]: Intel Corporation Ethernet Controller 10-Gigabit X540-AT2 [8086:1528] (rev 01)
81:00.1 Ethernet controller [0200]: Intel Corporation Ethernet Controller 10-Gigabit X540-AT2 [8086:1528] (rev 01)
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.