Linux查看MAC地址方法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux查看MAC地址方法相关的知识,希望对你有一定的参考价值。
参考技术A PS:一般默认的网卡文件名是eth0,根据IP地址对应的实际情况区判断是ethx即可。1、 ifconfig -a 其中 HWaddr字段就是MAC地址,这是最常用的方式
2、cat /etc/sysconfig/network-scripts/ifcfg-eth0(CentOS or Redhat配置文件)
下面两种在未设置IP前可以查看。可以用来解决MAC和操作系统绑定的问题。比如你把操作系统装到远程服务器,操作系统的mac地址是A主机的地址,在B主机上由于MAC地址不同无法远程启动(因为这时配置文件仍是A的mac地址)。由于OS在启动时会检测硬件,获得硬件的MAC地址,写到/sys/class/net/eth0/address文件中,我们在OS获得mac地址之后,使用原来的MAC配置文件之前(也就是/etc/sysconfig/network-scripts/ifcfg-eth0 ),把真正的mac地址写到配置文件中。
3、cat /sys/class/net/eth0/address 查看eth0的MAC地址
4、dmesg | grep eth0
dmesg’命令设备故障的诊断是非常重要的。在‘dmesg’命令的帮助下进行硬件的连接或断开连接操作时,我们可以看到硬件的检测或者断开连接的信息。
对dmesg命令感兴趣的小伙伴,可参考: https://www.cnblogs.com/zhaoxuguang/p/7810651.html
linux 下查看硬件信息(mac,IP地址,硬盘型号,序列号等)
一、查看网卡mac地址
#安装lshw
[[email protected] ~]# yum install lshw
#使用方法
[[email protected] ~]# lshw -c network *-network:0 description: Ethernet interface product: NetXtreme II BCM5709 Gigabit Ethernet vendor: Broadcom Limited physical id: 0 bus info: [email protected]:02:00.0 logical name: enp2s0f0 version: 20 serial: 00:26:55:31:a9:dc size: 1Gbit/s capacity: 1Gbit/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.2.6 duplex=full firmware=bc 4.6.4 NCSI 1.0.3 latency=0 link=yes multicast=yes port=twisted pair speed=1Gbit/s resources: irq:16 memory:f4000000-f5ffffff *-network:1 description: Ethernet interface product: NetXtreme II BCM5709 Gigabit Ethernet vendor: Broadcom Limited physical id: 0.1 bus info: [email protected]:02:00.1 logical name: enp2s0f1 version: 20 serial: 00:26:55:31:a9:de size: 1Gbit/s capacity: 1Gbit/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.2.6 duplex=full firmware=bc 4.6.4 NCSI 1.0.3 ip=10.0.100.85 latency=0 link=yes multicast=yes port=twisted pair speed=1Gbit/s resources: irq:17 memory:f2000000-f3ffffff *-network:0 description: Ethernet interface product: NetXtreme II BCM5709 Gigabit Ethernet vendor: Broadcom Limited physical id: 0 bus info: [email protected]:03:00.0 logical name: enp3s0f0 version: 20 serial: 00:26:55:31:a9:e0 size: 1Gbit/s capacity: 1Gbit/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.2.6 duplex=full firmware=bc 4.6.4 latency=0 link=yes multicast=yes port=twisted pair speed=1Gbit/s resources: irq:18 memory:f8000000-f9ffffff *-network:1 description: Ethernet interface product: NetXtreme II BCM5709 Gigabit Ethernet vendor: Broadcom Limited physical id: 0.1 bus info: [email protected]:03:00.1 logical name: enp3s0f1 version: 20 serial: 00:26:55:31:a9:e2 capacity: 1Gbit/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.2.6 firmware=bc 4.6.4 latency=0 link=no multicast=yes port=twisted pair resources: irq:19 memory:f6000000-f7ffffff
二、查看硬盘
#安装 smartmontools
yum install smartmontools -y
#使用方法
[[email protected] ~]# smartctl -a /dev/sda smartctl 6.2 2017-02-27 r4394 [x86_64-linux-3.10.0-514.26.2.el7.x86_64] (local build) Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org === START OF INFORMATION SECTION === Vendor: HP Product: LOGICAL VOLUME Revision: 2.74 User Capacity: 384,005,660,672 bytes [384 GB] Logical block size: 512 bytes Rotation Rate: 15000 rpm Logical Unit id: 0x600508b1001030393636354543300b00 Serial number: 50123456789ABCDE Device type: disk Local Time is: Wed Nov 8 16:10:00 2017 CST SMART support is: Unavailable - device lacks SMART capability. === START OF READ SMART DATA SECTION === Error Counter logging not supported Device does not support Self Test logging
#加-c参数
[[email protected] ~]# smartctl -x /dev/sda smartctl 6.2 2017-02-27 r4394 [x86_64-linux-3.10.0-514.26.2.el7.x86_64] (local build) Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org === START OF INFORMATION SECTION === Vendor: HP Product: LOGICAL VOLUME Revision: 2.74 User Capacity: 384,005,660,672 bytes [384 GB] Logical block size: 512 bytes Rotation Rate: 15000 rpm Logical Unit id: 0x600508b1001030393636354543300b00 Serial number: 50123456789ABCDE Device type: disk Local Time is: Wed Nov 8 16:12:07 2017 CST SMART support is: Unavailable - device lacks SMART capability. Read Cache is: Enabled Writeback Cache is: Disabled === START OF READ SMART DATA SECTION === Error Counter logging not supported Device does not support Self Test logging Device does not support Background scan results logging scsiPrintSasPhy Log Sense Failed [unsupported scsi opcode]
以上是关于Linux查看MAC地址方法的主要内容,如果未能解决你的问题,请参考以下文章
求一个linux c程序,来查看局域网的主机名和mac地址?