Linux查看⽹卡的MAC地址
如何使⽤命令查看⽹卡的MAC地址呢?下⾯总结⼀下查看⽹卡MAC地址的⽅式。
1:ifconfig命令查看⽹卡MAC地址
/sbin/ifconfig | grep HWaddr
或
/sbin/ifconfig | grep ether
有些Linux发⾏版本的MAC地址字段为HWaddr,有些Linux发⾏版本的MAC地址字段为ether。根据实际情况选择上⾯命令。[root@KerryDB ~]# ifconfig -a
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
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<UP,BROADCAST,RUNNING,MULTICAST> 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<link>
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: <LOOPBACK,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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: <LOOPBACK,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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版本命令
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论