35

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?

4
  • 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__
    Commented Dec 7, 2016 at 15:08
  • 2
    Or you can use ip link to show the MAC address. Commented Dec 7, 2016 at 15:10
  • 5
    What OS? ifconfig shows the ether or lladdr on both Mac OS X and OpenBSD.
    – thrig
    Commented Dec 7, 2016 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! Commented Dec 7, 2016 at 17:03

6 Answers 6

34

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.

3
  • 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
    Commented Dec 7, 2016 at 16:36
  • Is ifconfig still deprecated`It works like a charm.
    – Timo
    Commented May 3, 2021 at 7:19
  • @Timo Yes, it was deprecated 5 years ago and it is still now. ip is much more powerful.
    – dr_
    Commented May 9, 2021 at 17:30
13

For many linux systems ipconfig doesn't show the mac anymore. If that is the case for you, try:

ip -a link

1
  • Note that the user does not say what kind of Unix they are using, only that they use one that has ifconfig.
    – Kusalananda
    Commented Nov 30, 2022 at 8:52
10

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

  • ifconfig -a link

OpenBSD's ifconfig doesn't have this.

Further reading

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> 
3
  • Which part of this output is the MAC address?
    – FJC
    Commented Oct 18, 2022 at 8:50
  • third column... Commented Oct 18, 2022 at 10:00
  • Note that the user does not say what kind of Unix they are using, only that they use one that has ifconfig.
    – Kusalananda
    Commented Nov 30, 2022 at 8:51
0

To get direct MAC address from the interface name.

ifconfig eth9 | awk '/ether/ {print $2}'
0
-1

This worked for me:

dmesg | grep -oE 'mac=.*\w+' | cut -b '5-'
1
  • 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
    Commented Nov 30, 2022 at 8:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .