Linux check my mac address

Как узнать 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, сначала смотрим список интерфейсов:

ifconfig -a

Доступных интерфейсов два: enp0s7 (в вашем случае он может называться по другому) и lo (он же локальный хост, который одинаков практически для всех компьютеров). Нам нужен enp0s7.

MAC-адрес устройства виден уже сейчас в поле ether, но чтобы отобразить только его, воспользуемся такой командой:

ifconfig -a | grep ether | gawk »

MAC

Здесь grep принимает на вход то, что вывела команда ifconfig -a, находит строку, где есть ether, и передаёт на вход команде gawk, которая выбирает второе слово в принятой строке.

Как посмотреть MAC-адрес с помощью ip

Более новой в системах GNU/Linux (относительно ifconfig) является программа ip. Её принцип работы практически такой же. Отличается синтаксисом и выводимой информацией. И она установлена по умолчанию для всех систем. Для отображения сетевых интерфейсов нужно ввести команду:

ip -a

Здесь lo и enp0s7 расположены в обратном порядке.

Чтобы узнать MAC адрес сетевой карты Linux, вводим ту же самую конструкцию, только для этой команды:

ip MAC

Выводы

За то, как узнать MAC адрес в Linux, отвечают две консольные утилиты — ifconfig и ip. Первая может запускаться от имени администратора в некоторых дистрибутивах (например в Debian), а где-то вообще не быть установленной (Manjaro). Это связано с её отходом на второй план, поскольку ip является более новой программой и устанавливается по умолчанию во всех системах.

Читайте также:  Перезагрузка при установке линукс

Обнаружили ошибку в тексте? Сообщите мне об этом. Выделите текст с ошибкой и нажмите Ctrl+Enter.

Источник

How to List/Get/Display/Find MAC Address in Linux Using 11 Popular Methods

CyberITHub

In this article, I will take you through different ways to List/Get/Display/Find MAC Address in Linux. You might be aware of Ethernet Card/Network Card/NIC Controller which works at Network level and is responsible for communicating with other network devices in a Network Topology. It is used in Layer-2 Communication. You can find the usage of MAC address in wide range of Network Devices currently in use. This is typically in-line with IEEE 802 Network technologies.

What is MAC Address

MAC is abbreviated as Media Access Control. It is a unique 48 bit(6-byte) address assigned to a Network Interface. It is almost used in all the Network Devices which has network controller in it. It will always show in this form 00:07:Y7:1C:6L:03.

How to List/Get/Display/Find MAC Address in Linux Using 11 Popular Methods 1

Find MAC Address in Linux

Method 1: How to find MAC Address in Linux Using ifconfig command

If you want to check MAC Address of all the network interfaces in Linux using our traditional ifconfig command then you need to use ifconfig -a command as shown below.

[root@localhost ~]# ifconfig -a enp0s3: flags=4163 mtu 1500 inet 192.168.0.103 netmask 255.255.255.0 broadcast 192.168.0.255 ether 08:00:27:1d:8e:54 txqueuelen 1000 (Ethernet) RX packets 191611 bytes 240718576 (229.5 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 85455 bytes 10105585 (9.6 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 1000 (Local Loopback) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Please note that here I am using root user to run all the below commands.You can use any user with sudo access to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide sudo access to User.

Method 2: How to find an ethernet MAC Address in Linux Using ifconfig command

If you want to check the MAC Address of a specific network interface using ifconfig command then you need to use network interface name with ifconfig command as shown below. Here we are checking MAC Address of interface enp0s3 using ifconfig enp0s3 command.

[root@localhost ~]# ifconfig enp0s3 enp0s3: flags=4163 mtu 1500 inet 192.168.0.103 netmask 255.255.255.0 broadcast 192.168.0.255 ether 08:00:27:1d:8e:54 txqueuelen 1000 (Ethernet) RX packets 33568 bytes 12062979 (11.5 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 20124 bytes 4406857 (4.2 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Please note that you might find eth0 network interface in your system instead of enp0s3 . Hence Please use the network interface name with all the mentioned commands as per your system interface name or else none of the command will work.

Method 3: How to find MAC Address in Linux Using ip addr sh command

If you want to check the MAC address of all the network interfaces then you need to simply use ip addr sh command and check the MAC address from ether field as shown below.

[root@localhost ~]# ip addr sh 1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: enp0s3: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08:00:27:1d:8e:54 brd ff:ff:ff:ff:ff:ff inet 192.168.0.103/24 brd 192.168.0.255 scope global dynamic enp0s3 valid_lft 2947sec preferred_lft 2947sec

Method 4: How to find an ethernet MAC Address in Linux using ip addr sh command

If you want to check the MAC address of some specific network interface then you need to use the interface name with ip addr sh command and check the MAC address from ether field as shown below. In this example we are checking MAC address of enp0s3 network interface.

[root@localhost ~]# ip addr sh enp0s3 2: enp0s3: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08:00:27:1d:8e:54 brd ff:ff:ff:ff:ff:ff inet 192.168.0.103/24 brd 192.168.0.255 scope global dynamic enp0s3 valid_lft 2610sec preferred_lft 2610sec

Method 5: How to find MAC Address in Linux Using ip link show command

If you want to check the MAC address of all the network interfaces then you can use another useful ip link show command and check the MAC address from link/ether field as shown below.

[root@localhost ~]# 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 pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether 08:00:27:1d:8e:54 brd ff:ff:ff:ff:ff:ff

Method 6: How to find an ethernet MAC Address in Linux using ip link show command

If you want to check the MAC address of some specific network interface then you need to use the interface name with ip link show command and check the MAC address from ether field as shown below. In this example we are checking MAC address of enp0s3 network interface.

[root@localhost ~]# ip link sh enp0s3 2: enp0s3: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether 08:00:27:1d:8e:54 brd ff:ff:ff:ff:ff:ff

Method 7: How to find MAC Address in Linux using ethtool command

You can also use another useful linux tool called ethtool to find MAC address in Linux as shown below. Here I am checking MAC address of my ethernet card enp0s3 using ethtool command hence you need to mention your Interface name before running below command.

[root@localhost ~]# ethtool -P enp0s3 | awk '< print $NF >;' 08:00:27:1d:8e:54

Method 8: How to find MAC Address in Linux using Regex with ifconfig command

You can use a simple grep regular expression with ifconfig command to find the MAC Address of an ethernet card in Linux as shown below. Like above example, Here I am using regular expression on my System enp0s3 interface so you need to change and mention your interface name instead of enp0s3 before running below command.

[root@localhost ~]# ifconfig enp0s3 | grep -o -E '([[:xdigit:]]:)[[:xdigit:]]' 08:00:27:1d:8e:54

Method 9: How to find MAC Address in Linux using SYS Files

If you want to check MAC address in Linux using SYS files you need to check network address file using below cat command. As mentioned below SYS file is a text file so its contents can always be seen through Linux cat command.

[root@localhost ~]# cat /sys/class/net/enp0s3/address 08:00:27:1d:8e:54

Method 10: How to find MAC Address in Linux using AWK Regex with ifconfig command

You can also use AWK regular expression with ifconfig command to find MAC Address in Linux as shown below. Here we are grepping ether keyword from ifconfig command and then piping to awk to get first and second column output separated by tab.

[root@localhost ~]# ifconfig enp0s3 | grep -i ether | awk '' ether 08:00:27:1d:8e:54 

Method 11: How to find MAC Address in Linux using Sed Regex with ifconfig command

Like above example, you can also use Sed Regular expressions with ifconfig command to find MAC Address in Linux as shown below.

[root@localhost ~]# ifconfig -a enp0s3 | grep ether | sed '/^.*ether */!d; s///;q' 08:00:27:1d:8e:54 txqueuelen 1000 (Ethernet)

Popular Recommendations:-

Читайте также:  What is libevent in linux

Источник

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

Find Linux System MAC Address

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.

Читайте также:  Самые распространенные linux дистрибутивы

Another useful command is the ip link which only focuses on the MAC address and does not display the IP addresses.

Show Linux System MAC Address

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.

Check Linux System MAC Address

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.

Источник

Оцените статью
Adblock
detector