Linux系统下更改网卡MAC地址

本文讲解了如何在 Linux系统下修改MAC地址

  • 系统环境: Debian 12
  • 网卡型号: 此办法适用于 Mellanox connectx的4/5/6/7代网卡
  • 刷新方案: 刷新MAC地址需要安装MFT工具, mft-4.26.1-3-x86_64-deb.tgz

安装mft工具方法如下:

解压安装包

root@vxworks:~/mft# tar zxvf mft-4.26.1-3-x86_64-deb.tgz
root@vxworks:~/mft# cd mft-4.26.1-3-x86_64-deb/
root@vxworks:~/mft/mft-4.26.1-3-x86_64-deb# ls
DEBS  install.sh  LICENSE.txt  old-mft-uninstall.sh  SDEBS  uninstall.sh
root@vxworks:~/mft/mft-4.26.1-3-x86_64-deb#

安装编译环境

root@vxworks:~/mft/mft-4.26.1-3-x86_64-deb# apt install gcc make dkms
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
.......
/etc/kernel/header_postinst.d/dkms:
dkms: running auto installation service for kernel 6.1.0-18-amd64.
dkms: autoinstall for kernel: 6.1.0-18-amd64.
Setting up linux-headers-amd64 (6.1.76-1) ...
Processing triggers for man-db (2.11.2-2) ...
Processing triggers for libc-bin (2.36-9+deb12u4) ...
root@vxworks:~/mft/mft-4.26.1-3-x86_64-deb#

安装mft工具

root@vxworks:~/mft/mft-4.26.1-3-x86_64-deb# ./install.sh 
-I- Removing mft external packages installed on the machine
-I- Installing package: /root/mft/mft-4.26.1-3-x86_64-deb/SDEBS/kernel-mft-dkms_4.26.1-3_all.deb
-I- Installing package: /root/mft/mft-4.26.1-3-x86_64-deb/DEBS/mft_4.26.1-3_amd64.deb
-I- In order to start mst, please run "mst start".

root@vxworks:~/mft/mft-4.26.1-3-x86_64-deb# 
root@vxworks:~/mft/mft-4.26.1-3-x86_64-deb# mst status
MST modules:
------------
    MST PCI module is not loaded
    MST PCI configuration module loaded

PCI Devices:
------------

/dev/mst/mt4119_pciconf0   - PCI conf iguration cycles access .
                             domain🚌dev.fn=0000:3b:00.0 addr.reg=88 data.reg=92 cr_bar.gw_offset=-1
                             Chip revision is: 00

root@vxworks:~/mft/mft-4.26.1-3-x86_64-deb#

刷新MAC地址

关闭写保护:

root@vxworks:~#flint -d /dev/mst/mt511_pciconf0 -ocr hw set Flash0.WriteProtected=Disabled

刷MAC:

root@vxworks:~#flint -d /dev/mst/mt511_pciconf0 –mac 0000709CD1C9B5E8 –ocr sg

重置FW:

root@vxworks:~#mlxfwreset –d /dev/mst/mt511_pciconf0 r

这样mac地址应该已经生效了,请重启再重新检查一下。

注意:加粗部分根据实际情况修正,mst status可获取到实际的设备名称

原文地址: Linux系统下更改网卡MAC地址