Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to get the default MAC address in Linux system

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article analyzes "how the Linux system gets the default MAC address". The content is detailed and easy to understand. Friends who are interested in "how to get the default MAC address in the Linux system" can follow the editor's train of thought to read it in depth. I hope it will be helpful to everyone after reading. Let's follow the editor to learn more about "how the Linux system obtains the default MAC address".

How to get the default MAC address in Linux system? Contact with MAC addresses cannot be avoided in embedded learning.

Brief introduction of MAC address:

The MAC (Media Access Control or Medium Access Control) address is a physical address fixed in the serial EEPROM on the network card, usually 48 bits long, used to define the location of the network device, used to represent the identifier of each site on the Internet, represented by hexadecimal numbers.

In the OSI model, the third network layer is responsible for the IP address, and the second data link layer is responsible for the MAC address.

So a host will have an MAC address, and each network location will have an IP address dedicated to it. Once any network device (such as network card, router) is produced, its MAC address is always unique and can not be changed by the user.

Figuratively speaking, the MAC address is like our ID card number, with global uniqueness.

Linux system to obtain the default MAC address method: first, the scope of application

This paper mainly introduces the method of reading the MAC address of the network card, which is suitable for the EasyARM-i.MX287A development kit, and its application principle and supporting examples are also applicable to the product models listed in Table 1.1.

Introduction of the principle

MAC (Media Access Control, Media access Control) is used to define the location of network devices. The identifier used to represent each site on the Internet, expressed in hexadecimal numbers, with a total of six bytes (48 bits). Among them, the first three bytes are the codes assigned by IEEE's registration authority RA to different manufacturers (high 24 bits), also known as "compiling unique identifiers" (Organizationally Unique Identifier), and the last three bytes (low 24 bits) are assigned to the production adapter interface by each manufacturer, called extended identifiers (uniqueness). An address block can generate 2 ^ 24 different addresses. The MAC address is actually the adapter address or adapter identifier. MAC is globally unique.

"default MAC of network card" is a function developed by Guangzhou Zhiyuan Electronics Co., Ltd. for Awork development kit and M283, M287 industrial control core board. The MAC address of the network card is stored through the OTP of the chip. The first two bytes of the MAC address of the core board and development kit of our company are fixed as "0x00" and "0x04". The last four bytes are saved in OTP. This document mainly describes how to read the MAC address of the network card by operating OTP.

After the kernel configures the OTP option, after the compiled kernel starts, the OTP device files are exported in the file system and the information is read by manipulating these device files. The registered network card MAC information can be first solidified into OTP and can be read in the application layer. The lower 4 bits of the MAC0 address can be read through the device file "/ sys/fsl_otg/SBK0", and the lower 4 bits of the MAC1 address can be read through the device file "/ sys/fsl_otg/SBK1".

Note: if you are using M287 or M283 industrial control boards, you do not need to configure the kernel.

III. Technical realization

Kernel compilation

1. Configure the kernel

Enter the linux-2.6.35.3 directory. Execute make menuconfig to configure the kernel. The configuration steps are as follows:

Sok@zlgmcu:~$ cd linux-2.6.35.3/ sok@zlgmcu:~/linux-2.6.35.3$ make menuconfig press enter to enter the Device Drivers option, as shown in figure 1 below.

Figure 1 Kernel configuration

Press enter to enter the Chracter devices option. As shown in figure 2 below.

Figure 2 Kernel configuration

Press the spacebar to select the Freescale On-Chip OTP Memory Support option, as shown in figure 3 kernel configuration figure 3.

Figure 3 Kernel configuration

Press enter to save exit.

two。 Compile the kernel

Execute the following command to compile the kernel in the current directory, and refer to the command as follows:

The vmuser@Linux-host:~/ linux-2.6.35.3$ make clean vmuser@Linux-host:~/ linux-2.6.35.3$ make uImage kernel firmware is located in "arch/arm/boot/uImage" and writes the generated kernel firmware to NANDFlash via TF card.

4. Read MAC actual operation

The following describes the process of reading the MAC of the network card, which is essentially the operation of OTP device files.

Execute MAC script file

Copy the MAC.sh file under this document directory to the EasyARM-i.MX287A development suite via U disk or TF card, and change the file permission to executable permission. Refer to the command as follows:

After root@EasyARM-iMX28x ~ # chmod 777 MAC.sh root@EasyARM-iMX28x ~ # / MAC.sh executes, look at the network devices, and the MAC is shown in figure 5.

Fig. 5 Network equipment diagram

View the "/ sys/fsl_otp/HW_OCOTP_SRK1" and "/ sys/fsl_otp/HW_OCOTP_SRK0" devices. It can be found that the lower 4 bits of the network card MAC are actually the values stored in the OTP, as shown in figure 6.

Fig. 6 OTP read diagram

On the Linux system how to get the default MAC address to share here, I hope that the above content can make you improve. If you want to learn more knowledge, please pay more attention to the editor's updates. Thank you for following the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report