[HowTo] Get MAC Address on Linux and BSD Systems: Complete Guide

Table of Contents

Introduction

A MAC address is a unique code that identifies your network card. This code helps devices talk to each other on a network. Knowing how to find MAC addresses helps with fixing network problems, setting up security, and managing computers. In this guide, we’ll show you several ways to get MAC address information on different Linux systems and BSD operating systems. Moreover, we’ll make sure these methods work with various network setups and tools.

Whether you’re using Ubuntu for networking, CentOS systems, FreeBSD servers, or other platforms, learning about MAC address lookup is important for managing networks well. Since computer management often requires quick access to hardware information, having multiple methods available ensures you can always find what you need.

Methods to Get MAC Address on Linux

Linux offers several terminal commands and methods to find MAC address information. Each approach has its own benefits, and all work across different Linux versions. However, some methods may need extra software to be installed first. Since different network setups require different tools, having multiple options ensures you can always get the information you need.

Using ip Command

The ip command is the new way to do what ifconfig used to do. It’s included by default on most Linux systems. In addition, it’s part of the iproute2 package. Because it’s so widely available, this makes it a reliable choice for most situations.

lc-root@ubuntu:~$ ip link show
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s3:  mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:4c:8a:23 brd ff:ff:ff:ff:ff:ff

To get the MAC address for a specific network connection, you can use this command:

lc-root@ubuntu:~$ ip link show enp0s3 | grep link/ether | awk '{print $2}'

Using ifconfig Command

The ifconfig command is older software, yet it’s still available on many systems. It provides a simple way to view network connection details. Although it’s been replaced by newer tools, many computer managers still use it because it’s familiar and easy to understand.

lc-root@ubuntu:~$ ifconfig -a
enp0s3: flags=4163  mtu 1500
        inet 192.168.1.100  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::a00:27ff:fe4c:8a23  prefixlen 64  scopeid 0x20
        ether 08:00:27:4c:8a:23  txqueuelen 1000  (Ethernet)
        RX packets 12345  bytes 1234567 (1.2 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6789  bytes 987654 (987.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Using nmcli Command

NetworkManager’s terminal tool offers detailed device information. It’s especially helpful on systems that use NetworkManager for network control. When you’re working with modern Linux versions, this tool provides complete network details that other commands might not show.

lc-root@ubuntu:~$ nmcli device show enp0s3
GENERAL.DEVICE:                         enp0s3
GENERAL.TYPE:                           ethernet
GENERAL.HWADDR:                         08:00:27:4C:8A:23
GENERAL.MTU:                            1500
GENERAL.STATE:                          100 (connected)
GENERAL.CONNECTION:                     Wired connection 1
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/1

Using ethtool Command

The ethtool command gives detailed network card information. Moreover, it can show permanent MAC addresses even when network connections are not active. This makes it particularly useful for fixing problems or when you need the hardware address no matter what the connection status is.

lc-root@ubuntu:~$ ethtool -P enp0s3
Permanent address: 08:00:27:4c:8a:23

Reading /sys Filesystem

For computer programs or when other tools aren’t available, you can directly read MAC addresses from the Linux system files. This method works at the most basic level and doesn’t require any special tools to be installed.

lc-root@ubuntu:~$ cat /sys/class/net/enp0s3/address
08:00:27:4c:8a:23

To list all network connections along with their MAC addresses, you can use a simple loop:

lc-root@ubuntu:~$ for iface in /sys/class/net/*; do echo -n "$(basename $iface): "; cat $iface/address; done

Distribution-Specific Examples

Different Linux versions may have different default network tools and ways of naming network cards. Here are examples for popular Linux versions. While most commands work on all versions, some tools are more common on certain systems.

Ubuntu and Debian

Ubuntu and Debian systems usually use standard network card names and NetworkManager. Since these are very popular systems, knowing their network tools is very helpful.

lc-root@ubuntu:~$ ip link show
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s3:  mtu 1500 qdisc fq_codel state UP
    link/ether 08:00:27:4c:8a:23 brd ff:ff:ff:ff:ff:ff

CentOS and RHEL

Red Hat-based systems use NetworkManager and may have different network card naming. When working in business settings, these tools are very important for computer management.

[lc-root@centos ~]$ nmcli device show ens192
GENERAL.DEVICE:                         ens192
GENERAL.TYPE:                           ethernet
GENERAL.HWADDR:                         00:50:56:8C:12:A4
GENERAL.MTU:                            1500
GENERAL.STATE:                          100 (connected)

Fedora

Fedora uses NetworkManager and systemd network service, with modern network card naming. As a system that gets new features first, it often has the latest network tools.

[lc-root@fedora ~]$ ip link show enp1s0
2: enp1s0:  mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 52:54:00:12:34:56 brd ff:ff:ff:ff:ff:ff

openSUSE

openSUSE uses a network management tool and may have different network card naming. Although fewer people use it, it has strong business features that make it useful for certain jobs.

lc-root@opensuse:~> ip address show eth0
2: eth0:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:ab:cd:ef brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.101/24 brd 192.168.1.255 scope global eth0

Arch Linux

Arch Linux uses systemd network service and standard network card names. While it needs more hands-on setup, it gives users full control over their computer settings.

[lc-root@archlinux ~]$ ethtool -P enp2s0
Permanent address: 00:1B:21:0F:1A:2B

FreeBSD

FreeBSD uses traditional BSD-style network tools and network card naming rules. Unlike Linux systems, it keeps working with older network programs that many computer managers still like to use.

root@freebsd:~ # ifconfig em0
em0: flags=8843 metric 0 mtu 1500
        options=9b
        ether 08:00:27:4c:8a:23
        inet 192.168.1.102 netmask 0xffffff00 broadcast 192.168.1.255
        media: Ethernet autoselect (1000baseT )
        status: active
        nd6 options=29

To get just the MAC address, you can filter the output:

root@freebsd:~ # ifconfig em0 | grep ether | awk '{print $2}'

Troubleshooting

If you’re having trouble finding MAC addresses, consider these common problems and their solutions. Sometimes the issue might be with user rights, or the network card might not be working as expected.

  • Network card not found: First, check the card name using ip link show or nmcli device status. The card might have a different name than you expect.
  • Access denied: Some commands may need admin rights to work properly. Try running the command with sudo if you don’t already have special rights.
  • Card not active: Use ethtool -P to get the permanent address even when the network link is not working. This works because it reads the hardware address straight from the device.
  • Fake network cards: Remember that fake network cards like bridges or VLANs may not have real hardware MAC addresses. In these cases, you’ll need to check the real network cards instead.

Best Practices

Follow these tips for effectively managing MAC address lookup in Linux environments. By following these practices, you’ll get reliable and consistent results across different systems.

  • Use the ip command as your main method for current Linux systems, since it’s the most widely available and modern tool.
  • Choose ethtool -P for permanent hardware addresses that stay the same even when network cards change status. This ensures you get the real hardware address, not a temporary one.
  • Use nmcli when working with NetworkManager-controlled connections, as it provides the most complete information in those environments.
  • Add network card checks in your programs to avoid errors with missing devices. This stops your automated tasks from breaking when network cards aren’t available.
  • Think about using permanent addresses for network setup and security rules, since they stay the same after computer restarts and network card changes.

Conclusion

Finding MAC addresses on Linux becomes simple once you learn the available tools and methods. The ip command provides the most general solution, while special tools like nmcli and ethtool offer extra features for specific situations. Understanding these approaches across different Linux versions ensures you can effectively fix network problems, set up security policies, and manage computer networking no matter which Linux version you’re using. Regular practice with these commands will make your network management work more efficient and reliable. By learning these techniques, you’ll be ready to handle any networking challenge that comes up.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.