How to find the MAC address of your Raspberry Pi
You sometimes need to find out the MAC address of your Raspberry Pi. For instance, you want to find it among the list of devices attached to your LAN, because you want your router’s DHCP service to assign your RPi a permanently dedicated IP address instead of letting the DHCP just assign it the next available IP address each time you start it up. Then you can SSH into the same IP address each time to log into your RPi from your PC or Mac knowing it will always be there, without having to search for the RPi on the network.
Some LANs are configured to allow access only for a white-listed devices by MAC address, so you’ll also need to know yours to be able to use such a LAN.
A MAC address (media access control address) is a unique identifier used as a network address for most IEEE 802 network technologies, including Ethernet. MAC addresses are most often assigned by the manufacturer of a network interface controller (NIC) and are stored in its hardware, such as the card’s read-only memory or some other firmware mechanism. Its like a fingerprint in that its guaranteed that no other device will have the same MAC address as yours.
The MAC address is contained in the system info file
/sys/class/net/eth0/address
which you can display using
cat /sys/class/net/eth0/address
Or from the command line you can simply use the following command :
ifconfig eth0
This will display results something like this :
eth0 Link encap:Ethernet HWaddr b7:30:cf:f1:7d:b4 inet addr:192.168.0.24 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::ba27:ebff:fefc:9fd2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:336 errors:0 dropped:0 overruns:0 frame:0 TX packets:304 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:27045 (26.4 KiB) TX bytes:43758 (42.7 KiB)
The “HWaddr” in the display represents the device’s MAC address. In this example its “b7:30:cf:f1:7d:b4″
Any comments ? Feel free to leave a reply below…
Very helpful. Thank you for this.
correct
Yeah. Useful for me too
Thanx. Helped a lot.
Nice one thanks mate.
This is useful, but it only gets the MAC address that is saved to a file. Files can be changed. How does one get the “true” MAC address from the firmware?
But how is it determined in the first place?
Another way,
echo $(cat /sys/class/net/eth0/address)
and you can save it to a variable,
MAC=$(cat /sys/class/net/enx*/address)
, where eth0/enx* is the interface (wlan0, eth0, enx*)
Thank you.
Very helpful