33

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?

Tom Scott
  • 445
  • 1
  • 5
  • 7
  • 1
    Show 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
  • 2
    Or you can use `ip link` to show the MAC address. – Johan Myréen Dec 07 '16 at 15:10
  • 5
    What 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 Answers6

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
  • Is `ifconfig` still deprecated`It works like a charm. – Timo May 03 '21 at 07:19
  • @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
9

The command that you want on MacOS, FreeBSD, and TrueOS is:

  • ifconfig -a link

OpenBSD's ifconfig doesn't have this.

Further reading

JdeBP
  • 66,967
  • 12
  • 159
  • 343
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
0

To get direct MAC address from the interface name.

ifconfig eth9 | awk '/ether/ {print $2}'
Kusalananda
  • 320,670
  • 36
  • 633
  • 936
-1

This worked for me:

dmesg | grep -oE 'mac=.*\w+' | cut -b '5-'
  • 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