10

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?

Bex
  • 2,929
  • 3
  • 26
  • 34

3 Answers3

10

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
...
LotPings
  • 366
  • 1
  • 13
9

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)
else
    MAC=$(cat /sys/class/net/wlan0/address)
fi

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.

Milliways
  • 62,573
  • 32
  • 113
  • 225
7

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

To show the wlan0 interface:

ip link show wlan0

or

cat /sys/class/net/wlan0/address

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

MatsK
  • 2,882
  • 3
  • 17
  • 22