I want to determine the MAC-address of my Wi-Fi interface on a Raspberry Pi Z W running Raspbian Lite.

Is there a command that I can run to tell me this? Is there a device in the /proc tree that will disclose it?

  • 1
    Enter in terminal ifconfig wlan0 At the end of the first line should be the hardware address aka MAC. – LotPings Aug 29 '17 at 10:20
  • 2
    @LotPings You could make that an answer! – joan Aug 29 '17 at 10:23

The following is a fragment of a bash script I use to determine the MAC of Ethernet, or if this does not exist of WiFi (for Pi Zero W).

It does not rely on ifconfig or any other method of detecting allocated IP, and just needs the system to detect the networking hardware.

This works for Jessie, Stretch or Buster

# Find MAC of eth0, or if not exist wlan0
if [ -e /sys/class/net/eth0 ]; then
    MAC=$(cat /sys/class/net/eth0/address)
elif [ -e /sys/class/net/enx* ]; then
    MAC=$(cat /sys/class/net/enx*/address)
    MAC=$(cat /sys/class/net/wlan0/address)

Basically you could use MAC=$(cat /sys/class/net/wlan0/address) to find the MAC of inbuilt WiFi on Pi3 or Pi Zero W.

MAC=$(cat /sys/class/net/wlx*/address) should work on WiFi dongles on Stretch, but you could easily adapt the above to work on both Jessie or Stretch for WiFi and Ethernet.

  • Very good answer. Thank you! Does Raspbian Stretch use predictable network interface names? Do they affect the naming of the structure under /sys/class/net? – Bex Aug 30 '17 at 7:26
  • 1
    @Bex It depends; a fresh install uses predictable network interface names by default, I do not know about upgrades. It is simple to restore former behaviour, see How do I set up networking/WiFi/Static IP for detail. Whatever name is selected by the hardware enumeration process should be shown. There are several methods of modifying this process. – Milliways Aug 30 '17 at 7:44

Enter in terminal/console ifconfig wlan0 At the end of the first line should be the hardware address aka MAC.

Here a sample output (German locale):

pi@RasPi0w-1:~ $ ifconfig wlan0
wlan0     Link encap:Ethernet  Hardware Adresse b8:27:eb:xx:xx:xx
  • I have upvoted this answer - but I don't think ifconfig is a good alternative going forward. – Bex Aug 30 '17 at 7:13
  • 1
    Agreed, luckily there are two alternatives. – LotPings Aug 30 '17 at 7:16

Many distros is replacing ifconfig with ip so I would discourage the use of ifconfig.

To show the wlan0 interface:

ip link show wlan0


cat /sys/class/net/wlan0/address

Ref: https://www.linux.com/learn/replacing-ifconfig-ip

  • I'm pretty sure ifconfig will still be available for many years. Removing it will save a measly 800 kB, breaking a lot of old scripts. – Dmitry Grigoryev Aug 29 '17 at 15:22
  • Problem is, that person would want a salary. – Dmitry Grigoryev Aug 29 '17 at 15:26
  • 1
    To continue to use a deprecated command in new implementations is sad. I have seen this in work related situations, and its like pushing the problem in front of you, and at a point in time it will get to big! Start dealing with it instead! – MatsK Aug 29 '17 at 16:29
  • 2
    In this case, ip link show is probably more appropriate than ip addr show. – Bob Aug 30 '17 at 0:40
  • 1
    In my desktop system I run Debian Stretch, that does not seem to have ifconfig by default anymore, Raspbian Stretch seem to have it. I prefer ip over ifconfig, though I think Bob is right in saying that link is probably more appropriate than addr in this context. The solution I did go for, though, was to read it from /sys/class/net/wlan0/address - no additional parsing necessary. Additionally, I write it as cat /sys/class/net/wl*/address in a naïve attempt to make it save for the coming "predicable network interface names". – Bex Aug 30 '17 at 7:20

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.