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?
Asked
Active
Viewed 1.4e+01k times
33
-
1Show us the output of `ifconfig` for you machine. The 'HWaddr' field will be your MAC address. Dont forget to run as root. – jc__ Dec 07 '16 at 15:08
-
2Or you can use `ip link` to show the MAC address. – Johan Myréen Dec 07 '16 at 15:10
-
5What OS? `ifconfig` shows the `ether` or `lladdr` on both Mac OS X and OpenBSD. – thrig Dec 07 '16 at 15:26
-
as @jc__ mentioned - show us the output of `ifconfig -a`, (and `ip 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! – Michael Felt Dec 07 '16 at 17:03
6 Answers
30
First, your computer doesn't have a MAC address. Each network card has a MAC address. So if your machine has a wireless card and an Ethernet card, it'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.
dr_
- 28,763
- 21
- 89
- 133
-
Just as a nit, I recall at least some Sun machines that had a MAC address built into the machine, that was used on all interfaces – infixed Dec 07 '16 at 16:36
-
-
@Timo Yes, it was deprecated 5 years ago and it is still now. `ip` is much more powerful. – dr_ May 09 '21 at 17:30
12
For many linux systems ipconfig doesn't show the mac anymore. If that is the case for you, try:
ip -a link
Gabriel Fair
- 351
- 4
- 14
-
Note that the user does not say what kind of Unix they are using, only that they use one that has `ifconfig`. – Kusalananda Nov 30 '22 at 08:52
9
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
5
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>
Krishna
- 161
- 1
- 5
-
-
-
Note that the user does not say what kind of Unix they are using, only that they use one that has `ifconfig`. – Kusalananda Nov 30 '22 at 08:51
0
To get direct MAC address from the interface name.
ifconfig eth9 | awk '/ether/ {print $2}'
Kusalananda
- 320,670
- 36
- 633
- 936
Shrikant B
- 1
- 2
-1
This worked for me:
dmesg | grep -oE 'mac=.*\w+' | cut -b '5-'
Micael Illos
- 99
-
Your answer is a bit terse and could be improved by explaining the code. Note too that the user in the question does not say they are on a specific type of Unix, only one that has `ifconfig`. – Kusalananda Nov 30 '22 at 08:50