🗺️博客地图
在实际生产过程中,由于某些原因可能需要修改网卡的 MAC 地址。本文介绍两种修改Intel网卡MAC地址的方法
方法一:ethtool命令
1、备份网卡eeprom,运行命令:
ethtool -e 网口名称 raw on > 网口名称.data
例如:ethtool -e eth5 raw on > /root/backup/eth5.data
2、检查网卡mac地址在网卡eeprom中的偏移量,运行命令:
ethtool -e 网口名称 | grep "mac地址"
例如:ethtool -e eth5 | grep "5c 35 9f 48 e2 11")
查看mac地址偏移量是否符合下面的要求
3、检查网卡的magic值( VenID与DevID ),magic值可以通过命令lspci -nn -vv | grep Eth查询,下列示例的magic需要根据实际情况进行修改,macgic值得确认
[root@localhost ~]# lspci -nn -vv | grep Eth
pcilib: sysfs_read_vpd: read failed: Input/output error
0b:00.0 Ethernet controller [0200]: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection [8086:10fb] (rev 01)
Subsystem: Intel Corporation Ethernet Server Adapter X520-2 [8086:000c]
13:00.0 Ethernet controller [0200]: VMware VMXNET3 Ethernet Controller [15ad:07b0] (rev 01)
Subsystem: VMware VMXNET3 Ethernet Controller [15ad:07b0]
通过ethtool -i网卡名称 可以知道0b:00.0才是我们需要的,0b:00.0 那一列中 中括号包围的部分就是DevID与VenID ([8086:10fb]),按0x VenID DevID拼接就是:0x10fb8086
5、修改网卡mac
如果网卡是82599或X520,使用ethtool -e p1p1(p1p1是第一个接口的名称,根据实际情况修改),检查偏移量为0x0360开始的6个字节是否是当前mac地址(把当前的mac记录下来,以便后续还原)
如果确认无误,82599或X520修改MAC地址可以依次执行下列命令,最后1列的值是改成的MAC
网卡 0xVenID与DevID 偏移量 字节 mac值
ethtool -E p1p1 magic 0x10fb8086 offset 0x360 length 1 value 0x48
ethtool -E p1p1 magic 0x10fb8086 offset 0x361 length 1 value 0xf8
ethtool -E p1p1 magic 0x10fb8086 offset 0x362 length 1 value 0xdb
ethtool -E p1p1 magic 0x10fb8086 offset 0x363 length 1 value 0x7e
ethtool -E p1p1 magic 0x10fb8086 offset 0x364 length 1 value 0xda
ethtool -E p1p1 magic 0x10fb8086 offset 0x365 length 1 value 0x5c
如果网卡是X550T,则需要更改上面的magic