小编给大家分享一下Linux系统中查看mac地址命令有哪些,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
MAC(Media Access Control,介质访问控制)是用来定义网络设备的位置。用来表示互联网上每一个站点的标识符,采用十六进制数表示,共六个字节(48位)。
1:ifconfig命令查看网卡MAC地址
/sbin/ifconfig | grep HWaddr
或
/sbin/ifconfig | grep ether
有些Linux发行版本的MAC地址字段为HWaddr,有些Linux发行版本的MAC地址字段为ether。根据实际情况选择上面命令。
[root@KerryDB ~]# ifconfig -a lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 1000 (Local Loopback) RX packets 858 bytes 72251 (70.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 858 bytes 72251 (70.5 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 p4p1: flags=4163 mtu 1500 inet 10.20.57.24 netmask 255.255.255.0 broadcast 10.20.57.255 inet6 fe80::b283:feff:fe55:32e5 prefixlen 64 scopeid 0x20 ether b0:83:fe:55:32:e5 txqueuelen 1000 (Ethernet) RX packets 6637181 bytes 1536293500 (1.4 GiB) RX errors 0 dropped 293652 overruns 0 frame 0 TX packets 4333535 bytes 1080300983 (1.0 GiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
如果想只提取网卡MAC地址,可以使用下面命令(用具体的网卡名替换xxx)
ifconfig xxx | grep -o -E ‘([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}’
[root@KerryDB tmp]# ifconfig p4p1 | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}' b0:83:fe:55:32:e5 [root@KerryDB tmp]#
方法2:/sys/class/net/xxx/address查看
根据网卡名调整,例如这里网卡名为ens160,如果网卡名为xxx,那么应该用/sys/class/net/xxx/address
# more /sys/class/net/ens160/address 00:50:56:95:5c:16 # cat /sys/class/net/eth0/address 00:50:56:b3:81:f8
方法3:ip命令查看网卡MAC地址
[root@KerryDB tmp]# ip link 1: lo:mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: p4p1:mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether b0:83:fe:55:32:e5 brd ff:ff:ff:ff:ff:ff [root@KerryDB tmp]# ip link show 1: lo:mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: p4p1:mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether b0:83:fe:55:32:e5 brd ff:ff:ff:ff:ff:ff [root@KerryDB tmp]# ip link show p4p1 2: p4p1:mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether b0:83:fe:55:32:e5 brd ff:ff:ff:ff:ff:f [root@KerryDB tmp]# ip link show p4p1 | awk '/ether/ {print $2}'; b0:83:fe:55:32:e5
4:nmcli命令查看网卡MAC地址
[root@KerryDB tmp]# nmcli device show p4p1 GENERAL.DEVICE: p4p1 GENERAL.TYPE: ethernet GENERAL.HWADDR: B0:83:FE:55:32:E5 GENERAL.MTU: 1500 GENERAL.STATE: 100 (connected) GENERAL.CONNECTION: p4p1 GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 WIRED-PROPERTIES.CARRIER: on IP4.ADDRESS[1]: 10.20.57.24/24 IP4.GATEWAY: 10.20.57.1 IP4.ROUTE[1]: dst = 10.20.57.0/24, nh = 0.0.0.0, mt = 100 IP4.ROUTE[2]: dst = 0.0.0.0/0, nh = 10.20.57.1, mt = 100 IP6.ADDRESS[1]: fe80::b283:feff:fe55:32e5/64 IP6.GATEWAY: -- IP6.ROUTE[1]: dst = ff00::/8, nh = ::, mt = 256, table=255 IP6.ROUTE[2]: dst = fe80::/64, nh = ::, mt = 256 [root@KerryDB tmp]# nmcli device show p4p1 | grep -i hw GENERAL.HWADDR: B0:83:FE:55:32:E5
注意:这里根据实际的网卡名进行调整,如果网卡名为ens160,那么上面命令需要调整为
# nmcli device show ens160 | grep -i hwaddr GENERAL.HWADDR: 00:50:56:B4:00:94
5:dmesg命令查看网卡MAC地址
[root@KerryDB tmp]# dmesg | grep eth [ 0.776155] r8169 0000:02:00.0 eth0: RTL8168g/8111g at 0xffffafbe80648000, b0:83:fe:55:32:e5, XID 0c000800 IRQ 27 [ 0.776158] r8169 0000:02:00.0 eth0: jumbo features [frames: 9200 bytes, tx checksumming: ko]
看完了这篇文章,相信你对“Linux系统中查看mac地址命令有哪些”有了一定的了解,如果想了解更多相关知识,欢迎关注编程网行业资讯频道,感谢各位的阅读!