如何在Linux操作系统下显示所有网卡列表?
您可以使用以下任一命令来列出 Linux 操作系统下安装的网卡。请注意,ifconfig和ip命令还将显示有关 vpn、环回和其他已配置接口的接口信息。
教程详情 | |
---|---|
难度级别 | 简单的 |
根权限 | 是的 |
要求 | Linux终端 |
操作系统兼容性 | Alma • Arch • Debian • Fedora • Linux • Mint • openSUSE • RHEL • Rocky • Stream • SUSE • Ubuntu |
美东时间。阅读时间 | 3分钟 |
- lspci command:列出所有PCI设备。
- lshw command:Linux识别以太网接口和NIC硬件。
- dmidecode command:列出 BIOS 中的所有硬件数据。
- ifconfig command:过时的网络配置实用程序。
- ip command:推荐新的网络配置实用程序。
- hwinfo command:探测 Linux 的网卡。
- ethtool command:请参阅 Linux 上的 NIC/卡驱动程序和设置。
我们使用标准术语,例如网络接口控制器 (NIC)。也称为网络接口卡、网络适配器、LAN 适配器或物理网络接口等。让我们看一些在 Linux 机器上显示 NIC 信息的有用示例。
使用lspci命令Linux命令显示网卡列表
键入以下 lspci 命令以及egrep 命令来过滤掉设备:我的 Linux 服务器的输出示例:
# lspci | egrep -i --color 'network|ethernet'
# lspci | egrep -i --color 'network|ethernet|wireless|wi-fi'
09:00.0 以太网控制器:Broadcom Corporation NetXtreme BCM5761e 千兆位以太网 PCIe (rev 10) 0c:00.0 网络控制器:Intel Corporation Ultimate N WiFi Link 5300
如何在 Linux 上使用 lshw 命令显示网卡 (NIC)
默认情况下,您的系统上可能未安装lshw 或 hwinfo命令。因此,在 Alpine Linux 上使用apk 命令,在 RHEL 和 co 上使用 dnf 命令/ yum 命令,在 Debian、Ubuntu 和 co 上使用 apt 命令/ apt-get 命令,在 SUSE/OpenSUSE 上使用 zypper 命令,在 Arch Linux 上使用 pacman 命令来安装lshw或硬件信息。
lshw 命令可以提取有关机器硬件配置(包括网卡)的详细信息。键入以下命令:
# lshw -class network
有关 Linux 上网卡的详细硬件信息:
*-网络已禁用 描述:无线接口 产品:Ultimate N WiFi Link 5300 供应商:英特尔公司 物理 ID:0 总线信息:pci@0000:0c:00.0 逻辑名称:wlan0 版本:00 序列号:00:21:6a:ca:9b:10 宽度:64 位 时钟:33MHz capabilities: pm msi pciexpress bus_master cap_list ethernet physical wireless configuration: broadcast=yes driver=iwlwifi driverversion=3.2.0-0.bpo.1-amd64 firmware=8.83.5.1 build 33692 latency=0 link=no multicast=yes wireless=IEEE 802.11abgn resources: irq:46 memory:f1ffe000-f1ffffff *-network description: Ethernet interface product: NetXtreme BCM5761e Gigabit Ethernet PCIe vendor: Broadcom Corporation physical id: 0 bus info: pci@0000:09:00.0 logical name: eth0 version: 10 serial: b8:ac:6f:65:31:e5 size: 1GB/s capacity: 1GB/s width: 64 bits clock: 33MHz capabilities: pm vpd msi pciexpress bus_master cap_list ethernet physical tp 10bt 10bt-fd 100bt 100bt-fd 1000bt 1000bt-fd autonegotiation configuration: autonegotiation=on broadcast=yes driver=tg3 driverversion=3.121 duplex=full firmware=5761e-v3.71 ip=192.168.1.5 latency=0 link=yes multicast=yes port=twisted pair speed=1GB/s resources: irq:48 memory:f1be0000-f1beffff memory:f1bf0000-f1bfffff
Here is another outputs:
$ sudo lshw -class network -short [sudo] password for vivek: H/W path Device Class Description =========================================================== /0/100/1d.6/0 wlp82s0 network Wi-Fi 6 AX200 /0/100/1f.6 eth0 network Ethernet Connection (7) I219-LM
Where,
- -class network : View all network cards on your Linux system
- -short : Display device tree showing hardware paths, very much like the output of HP-UX’s ioscan command.
Let us see mask, IP and other information set up for wlp82s0:
$ ip a show wlp82s0
Linux ethtool command for Ethernet hardware devices
Want to see/query or control network driver and hardware settings on Linux? Try the the ethtool command:
$ sudo ethtool enp0s31f6
And it spitted out tons of useful information for my Ethernet network card on Linux:
Settings for enp0s31f6: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supported pause frame use: No Supports auto-negotiation: Yes Supported FEC modes: Not reported Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Advertised pause frame use: No Advertised auto-negotiation: Yes Advertised FEC modes: Not reported Speed: 1000Mb/s Duplex: Full Port: Twisted Pair PHYAD: 1 Transceiver: internal Auto-negotiation: on MDI-X: off (auto) Supports Wake-on: pumbg Wake-on: g Current message level: 0x00000007 (7) drv probe link Link detected: yes
We can display driver information for network card too:
$ sudo ethtool -i eth0
$ sudo ethtool -i enp0s31f6
ifconfig and ip commands
To see all configured network devices, enter:
# ifconfig -a
OR
# ip link show
OR
# ip a
Sample outputs:
1: lo:mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: mtu 1500 qdisc mq state UP qlen 1000 link/ether b8:ac:6f:65:31:e5 brd ff:ff:ff:ff:ff:ff inet 192.168.1.5/24 brd 192.168.1.255 scope global eth0 inet6 fe80::baac:6fff:fe65:31e5/64 scope link valid_lft forever preferred_lft forever 3: wlan0: mtu 1500 qdisc noop state DOWN qlen 1000 link/ether 00:21:6a:ca:9b:10 brd ff:ff:ff:ff:ff:ff 4: pan0: mtu 1500 qdisc noop state DOWN link/ether 92:0a:e7:31:e0:83 brd ff:ff:ff:ff:ff:ff 5: vmnet1: mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000 link/ether 00:50:56:c0:00:01 brd ff:ff:ff:ff:ff:ff inet 192.168.121.1/24 brd 192.168.121.255 scope global vmnet1 inet6 fe80::250:56ff:fec0:1/64 scope link valid_lft forever preferred_lft forever 6: vmnet8: mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000 link/ether 00:50:56:c0:00:08 brd ff:ff:ff:ff:ff:ff inet 192.168.179.1/24 brd 192.168.179.255 scope global vmnet8 inet6 fe80::250:56ff:fec0:8/64 scope link valid_lft forever preferred_lft forever
Want to list all IP addresses and interfaces on Linux in a tabular format for better readability? Try:
$ ip -br -c link show
$ ip -br -c addr show
Listing network cards on Linux using hwinfo command
Open the terminal and then type:
$ sudo hwinfo --network --short
Sample outputs from my Ubuntu Linux 20.04 LTS:
network interface:
veth4cf4e314 Ethernet network interface
lxdbr0 Ethernet network interface
veth5ac9105a Ethernet network interface
veth0932715b Ethernet network interface
veth514990e6 Ethernet network interface
lo Loopback network interface
eth0 Ethernet network interface
veth844c4162 Ethernet network interface
vethe8d69a5f Ethernet network interface
We can now obtain more info for eth0 using the ip command:
$ ip a s eth0
My IP address assigned to eth0 are as follows::
2: eth0:mtu 9001 qdisc mq state UP group default qlen 1000 link/ether 0a:99:85:fc:11:57 brd ff:ff:ff:ff:ff:ff inet 172.26.9.151/20 brd 172.26.15.255 scope global dynamic eth0 valid_lft 3501sec preferred_lft 3501sec inet6 fe80::899:85ff:fefc:1157/64 scope link valid_lft forever preferred_lft forever
The /proc/net/dev file
The dev pseudo-file contains network device status information. This gives the number of received and sent packets, the number of errors and collisions and other basic statistics. Open the terminal and then type the following cat command or less command/more command:
$ cat /proc/net/dev
Stats:
Inter-| Receive | Transmit face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed lo: 20097 179 0 0 0 0 0 0 20097 179 0 0 0 0 0 0 vmnet8: 0 0 0 0 0 0 0 0 0 33 0 0 0 0 0 0 潘0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 wlan0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 eth0: 592509534 623058 0 0 0 0 0 1053 122269656 401567 0 0 0 0 0 0 vmnet1: 0 0 0 0 0 0 0 0 0 34 0 0 0 0 0 0
结论
我们了解了各种 Linux 命令来显示有关已安装和正在运行的网卡的信息。我会要求读者也使用 man 命令/help 命令查阅以下手册页:
$ man ip
$ man ifconfig
$ man lshw
$ man hwinfo