Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there a more efficient way to retrieve the MAC address of a NIC in Linux?

This works:

ip link show dev eth0 | awk ' /link\/ether/ { print $2 }'

but can it be found via something like:

cat /sys/net/something
share|improve this question
add comment

3 Answers

up vote 25 down vote accepted

It's at /sys/class/net/eth0/address (or more precisely /sys/devices/pciXXXX:XX/XXXX/net/eth0/address where the XXX is your PCI bus ID, but this varies between systems).

(Incidentally, I found this with find /sys -name eth0 and looking at the files in the directories identified.)

share|improve this answer
add comment

It's also available via ifconfig:

kce@thinkpad:~$ /sbin/ifconfig eth0 |grep HWaddr
eth0      Link encap:Ethernet  HWaddr 00:1e:37:cc:ce:cc  

Or if you want just the MAC address:

kce@thinkpad:~$ /sbin/ifconfig eth0 |awk '/HWaddr/{print $5}'
00:1e:37:cc:ce:cc
share|improve this answer
2  
Well, you still have to awk or cut it. Because the mac is at the end of line. –  brodul Sep 5 '11 at 18:58
add comment

if you can install moreutils package, there is a ifdata tool. Description says:

ifdata: get network interface info without parsing ifconfig output

Here's an example:

me@box:~$ ifdata -ph eth0
00:21:86:61:35:44
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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