您好,登錄后才能下訂單哦!
小編給大家分享一下Linux系統中查看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]#
根據網卡名調整,例如這里網卡名為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
[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
[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
[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地址命令有哪些”有了一定的了解,如果想了解更多相關知識,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。