After substantial research I still haven't found an answer to this query, how can I modify the command 'ifconfig' to show my computer's MAC address?
6 Answers
First, your computer doesn't have a MAC address. Your network card has a MAC address. So if you have a wireless card and an Ethernet card, you'll have two MAC addresses.
On Linux, either of these commands will show you the MACs of all network cards in your machine:
ifconfig | grep ether
ip link
ifconfig
is deprecated on Linux, so you should use ip
.
For many linux systems ipconfig
doesn't show the mac anymore. If that is the case for you, try:
ip -a link
The command that you want on MacOS, FreeBSD, and TrueOS is:
ifconfig -a link
OpenBSD's ifconfig
doesn't have this.
Further reading
ifconfig
. Mac OS 10 Manual Pages. Apple corporation. 2008.ifconfig
. FreeBSD Manual Pages. 2015.- https://unix.stackexchange.com/a/319354/5132
Instead of using ifconfig
, you can use ip
command.
ip -brief link
will show following output.
lo UNKNOWN 00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP>
enp1s0 DOWN xx:6a:64:43:d5:xx <NO-CARRIER,BROADCAST,MULTICAST,UP>
wlp2s0 UP xx:d1:6b:f2:03:xx <BROADCAST,MULTICAST,UP,LOWER_UP>
docker0 UP xx:42:33:81:52:xx <BROADCAST,MULTICAST,UP,LOWER_UP>
vethf34394f@if13 UP xx:79:65:3e:e0:xx <BROADCAST,MULTICAST,UP,LOWER_UP>
phy0.mon UNKNOWN xx:d1:6b:f2:03:xx <BROADCAST,MULTICAST,UP,LOWER_UP>
To get direct MAC address from the interface name.
ifconfig eth9 | grep ether | awk '{print $2}'
-
You don't need to
grep
when you're processing withawk
anyway:awk '/ether/{print $2}'
– AdminBeeAug 30, 2021 at 12:35 -
ifconfig
for you machine. The 'HWaddr' field will be your MAC address. Dont forget to run as root.ip link
to show the MAC address.ifconfig
shows theether
orlladdr
on both Mac OS X and OpenBSD.ifconfig -a
, (andip addr
if available) and we can help you better. MAYBE after looking at the output of this command (these commands) you will be able to answer your own question!