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?

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 7, 2016 at 15:08
  • 2
    Or you can use ip link to show the MAC address. Dec 7, 2016 at 15:10
  • 5
    What OS? ifconfig shows the ether or lladdr on both Mac OS X and OpenBSD.
    – thrig
    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! Dec 7, 2016 at 17:03
  • 1
    @NathanShoesmith It went alright, I'm doing my last hour right now. How long have you got left?
    – Tom Scott
    Feb 27, 2017 at 15:27

6 Answers 6

28

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.

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
    Dec 7, 2016 at 16:36
  • Is ifconfig still deprecated`It works like a charm.
    – Timo
    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_
    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

9

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> 
0

This worked for me:

dmesg | grep -oE 'mac=.*\w+' | cut -b '5-'
0

To get direct MAC address from the interface name.

ifconfig eth9 | grep ether | awk '{print $2}'
2
  • You don't need to grep when you're processing with awk anyway: awk '/ether/{print $2}'
    – AdminBee
    Aug 30, 2021 at 12:35
  • Thanks for your input.
    – Shrikant B
    Aug 31, 2021 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.