- 3 Ways to Find MAC Address In Linux
- Procedures to find MAC address in Linux
- What is MAC address?
- Find MAC address with ifconfig command in Linux
- Find MAC address for a specific interface with ifconfig command in Linux
- Find MAC address with ip link show command in Linux
- Find MAC address from /sys in Linux
- Difference between MAC address and IP address
- Как узнать MAC-адрес в Linux
- Как узнать MAC-адрес с помощью ifconfig
- Как посмотреть MAC-адрес с помощью ip
- Выводы
- How to Find Network MAC Address in Linux System
- Approaches to Finding MAC Address in Linux
- 1. Find Linux System Mac Address Using IP Command
- 2. Find Linux System Mac Address Using Ifconfig Command
3 Ways to Find MAC Address In Linux
How to list MAC address on Linux is a commonly asked question during a Linux job interview. Here are some methods to get the MAC address. These commands are safe to run without changing anything.
The following commands can get you the MAC address of your network interface in Linux.
If you’re new to the world of Linux, you can refer to “Mastering the Linux Command: A Beginner’s Guide.” This in-depth article will be your guiding light, providing you with the foundational knowledge and skills required to navigate and wield the Linux command line interface (CLI) effectively and with assurance.
Procedures to find MAC address in Linux
- Open the terminal application.
- Type ifconfig -a or ip link show or cat /sys/class/net/*/address command
- Press Enter to run the command.
- The output will display the MAC address for all the network interfaces.
What is MAC address?
From Wikipedia, A MAC address is the unique identifier that is assigned by the manufacturer to a piece of network hardware (like a wireless card or an ethernet card). MAC stands for Media Access Control, and each identifier is intended to be unique to a particular device.
The MAC address consists of six sets of two characters, each separated by a colon. 00:1B:44:11:3A:B7 is an example of a MAC address. The MAC address is usually printed on the card itself. The MAC address can also be found in the BIOS of the computer or device.
A MAC address can be used to uniquely identify a device on a network. This allows for better security and more efficient networking. MAC addresses are usually assigned by the manufacturer of the network adapter. However, it is possible to change the MAC address of a device.
Find MAC address with ifconfig command in Linux
The best Linux command to find MAC address is using ifconfig command. All we need is to open the terminal then type ifconfig -a in the prompt. The number next to ether is the MAC address. This command will list MAC address, IP address, MTU size and other information about a network interface.
ens1f0: flags=4163 mtu 1500
inet 10.124.202.230 netmask 255.255.255.128 broadcast 10.124.202.255
ether 70:ca:9b:ce:67:ae txqueuelen 1000 (Ethernet)
RX packets 12187970 bytes 7390885300 (6.8 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 16813496 bytes 16253942714 (15.1 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xb1960000-b197ffff
By default, the ifconfig command will display information for all the network interfaces on the Linux system.
If you receive a message “ifconfig command not found” when you try to use it, you can run the following command to install it.
On Debian based distros:
# apt update
# apt install net-tools
On Red Hat based distros:
# dnf install net-tools
Check this post to get more info about how to fix ifconfig command not found
Find MAC address for a specific interface with ifconfig command in Linux
You can append the name of the interface to the end of the command (e.g. “ifconfig eth0”) to view the MAC address about a specific interface.
So if you want to display information only for specific device like eth0, you can use this command ifconfig eth0.
$ ifconfig eth0
eth0: flags=4163 mtu 1500
inet 10.254.222.37 netmask 255.255.254.0 broadcast 10.254.223.255
ether fa:16:3e:18:3a:76 txqueuelen 1000 (Ethernet)
RX packets 94405374 bytes 5781082518 (5.3 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 23249315 bytes 1034177108 (986.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
The ifconfig command can be used to configure a network interface. The basic syntax for the ifconfig command is: ifconfig interface ip address netmask BROADCAST_ADDRESS
This will set the IP address, netmask and gateway for the specified network interface.You can also use the ifconfig command to enable or disable a network interface. The basic syntax for this is: ifconfig interface up or down
The “ifconfig” command is a command-line utility that is used to display information about your network interfaces. This command is available on most Unix-like operating systems, including Linux and macOS. We can also use ifconfig command to troubleshoot network issues.
Find MAC address with ip link show command in Linux
Another way to find MAC address in Linux is using “ip link show” command. The number next to link/ether is the MAC address. This command will list the interface status, MAC address, MTU size, etc.
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: ens1f0: mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether 70:ca:9b:ce:67:ae brd ff:ff:ff:ff:ff:ff
To view information about a specific network link, you can use the “ip link show” command followed by the name of the network interface. For example, if you want to view information about the eth0 interface, you can run the following command: “ip link show eth0”.
The following command lists the interface names on the left and the associated MAC addresses on the right.
ip -o link show |cut -d ‘ ‘ -f 2,20
lo: 00:00:00:00:00:00
eth0: 02:01:e4:a2:3a:31
Find MAC address from /sys in Linux
If you want to get MAC information about the network interface, you can use this command cat /sys/class/net/*/address .
sysfs is a virtual filesystem in Linux that provides a way to access and manipulate the parameters of devices. sysfs is mounted on /sys when your system boots.
The sysfs filesystem contains a directory for each device on your system. The name of the directory is the name of the device. The contents of the directory depend on the type of device.If you want to get information about the network interfaces on your system, you can cd to /sys/class/net/.
# cat /sys/class/net/ens1f0/address
70:ca:9b:ce:67:ae
$ cat /sys/class/net/*/address
02:01:e4:a2:3a:31
00:00:00:00:00:00
Difference between MAC address and IP address
MAC addresses are physical addresses, while ip addresses are logical addresses. MAC addresses are used to identify devices on a network, while ip addresses are used to identify the location of devices on a network.
The two most common types of ip addresses are IPv4 and IPv6. IPv4 is a 32-bit address that can support up to 4.3 billion unique addresses. IPv6 is a 128-bit address that can support up to 3.4×1038 unique addresses.
MAC addresses are assigned by the manufacturer of the device. Ip addresses can be assigned by the user or by the network administrator.
Как узнать MAC-адрес в Linux
В те времена, когда только проектировался Ethernet, предусматривалось применение уникального номера каждой сетевой карте, подключённой к нему. Назначался он при изготовлении платы. MAC-адрес используется для определения получателя и отправителя информации в Сети. И в этой статье речь пойдёт о том, как узнать MAC адрес в Linux.
Практически во всех операционных системах на основе ядра Linux используется две консольные утилиты, с помощью которых можно узнать аппаратный адрес карты: ifconfig и ip. Различные графические приложения этого типа используют их данные.
Как узнать MAC-адрес с помощью ifconfig
Одной из первых сетевых программ в истории Linux является ifconfig. В некоторых дистрибутивах она запускается только от имени администратора, а где-то вообще не установлена. Рассмотрим её инсталляцию и использование в Manjaro Linux.
Пакет, содержащий в себе некоторые сетевые утилиты (в том числе и ifconfig), в Manjaro- и Arch-подобных системах называется net-tools. Установим его.
А в Ubuntu- и Debian-подобных системах:
sudo apt install net-tools
Чтобы узнать MAC-адрес Linux, сначала смотрим список интерфейсов:
Доступных интерфейсов два: enp0s7 (в вашем случае он может называться по другому) и lo (он же локальный хост, который одинаков практически для всех компьютеров). Нам нужен enp0s7.
MAC-адрес устройства виден уже сейчас в поле ether, но чтобы отобразить только его, воспользуемся такой командой:
ifconfig -a | grep ether | gawk »
Здесь grep принимает на вход то, что вывела команда ifconfig -a, находит строку, где есть ether, и передаёт на вход команде gawk, которая выбирает второе слово в принятой строке.
Как посмотреть MAC-адрес с помощью ip
Более новой в системах GNU/Linux (относительно ifconfig) является программа ip. Её принцип работы практически такой же. Отличается синтаксисом и выводимой информацией. И она установлена по умолчанию для всех систем. Для отображения сетевых интерфейсов нужно ввести команду:
Здесь lo и enp0s7 расположены в обратном порядке.
Чтобы узнать MAC адрес сетевой карты Linux, вводим ту же самую конструкцию, только для этой команды:
Выводы
За то, как узнать MAC адрес в Linux, отвечают две консольные утилиты — ifconfig и ip. Первая может запускаться от имени администратора в некоторых дистрибутивах (например в Debian), а где-то вообще не быть установленной (Manjaro). Это связано с её отходом на второй план, поскольку ip является более новой программой и устанавливается по умолчанию во всех системах.
Обнаружили ошибку в тексте? Сообщите мне об этом. Выделите текст с ошибкой и нажмите Ctrl+Enter.
How to Find Network MAC Address in Linux System
The term MAC Address is a derived abbreviation for Media Access Control Address. The network interface controller (NIC) uses the MAC address as its assigned unique identifier within an existing network segment.
To practically relate to or understand what a MAC address is, think of it as the postal or physical address to a house. The house in this case is the network interface controller (NIC).
There is a key difference between MAC address and IP address and therefore we should not confuse the two. MAC address identifies the device you are using since it is imprinted on the device hardware whereas IP address identifies the connection status among devices seeking to communicate on an existing/configured network.
The MAC address of any device is represented by a 12-digit hexadecimal number. Its display includes a colon or hyphen after every two MAC address digits for easy readability.
For instance, a MAC address can be represented in the following manner.
aa:bb:cc:dd:ee:ff or gg-hh-ii-jj-kk-ll
Approaches to Finding MAC Address in Linux
Depending on the number of network interfaces on your Linux machine like Wi-Fi built-in and Ethernet port, your computer can be associated with more than one MAC Address.
1. Find Linux System Mac Address Using IP Command
The ip command is part of the iproute2 package and can be used to display both the MAC address and IP address of your Linux-powered machine using either of the following commands.
$ ip addr or $ ip address or $ ip address show
Depending on the network adapter or interface present, we can see the availed MAC addresses. In the above screen capture, three distinct MAC addresses can be identified from the ip address command.
Another useful command is the ip link which only focuses on the MAC address and does not display the IP addresses.
2. Find Linux System Mac Address Using Ifconfig Command
The ifconfig command is another effective approach to identifying the MAC address of your Linux machine. We however need to install it first since it is a member of the net-tools package and not installed on Linux by default.
$ sudo apt install net-tools [On Debian, Ubuntu and Mint] $ sudo yum install net-tools [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux] $ sudo emerge -a sys-apps/net-tools [On Gentoo Linux] $ sudo pacman -S net-tools [On Arch Linux] $ sudo zypper install net-tools [On OpenSUSE]
Once installed, run the ifconfig command to find the IP address and MAC address of your Linux system.
Different network interfaces or adapters showcase different MAC addresses as highlighted in the above screen capture.
We have successfully defined and understood how to get the MAC address(es) on our Linux machines.