1、修改虛擬機器的*.VMx檔案.
這種方法最值得推薦,因為這樣就類似於重新“燒錄”了VMware虛擬機器的“物理網卡ROM”。方法是:
分兩種情況:
a:
ethernet0.addressType = "static"
ethernet0.Address = "00:50:56:0A:0B:0C"
"static"說明VM的"物理網卡"的Mac是靜態設定的,你可以改成一個以005056開頭的另外一個Mac即可。改完啟動VM時如果問你SSID的話,選擇“Keep Always”。
b:
ethernet0.addressType = "generated"
uuid.location = "56 4d dc f1 ff aa 75 ea-f1 b9 ee 0d 68 9c 65 5c"
uuid.bios = "56 4d ed 23 13 8c 96 91-7c 68 b2 09 8b aa bb cc"
ethernet0.generatedAddress = "00:0c:29:aa:bb:cc"
"generated"說明VM的"物理網卡"的Mac是系統隨機動態設定的,你可以通過將uuid.bios後六位及ethernet0.generatedAddress後六位改成你想要改成的以000c29開頭的Mac即可。
2、修改Linux系統裡相關 /etc/sysconfig/network-scripts/ifcfg-eth0檔案Mac值.
vi /etc/sysconfig/network-scripts/ifcfg-eth0
MacADDR=xx:xx:xx:xx:xx:xx
:wq 儲存退出
reboot
3、修改Linux系統裡相關rc.local檔案Mac值
通過寫指令碼的方法即可
4、其它方法
- 方法1:
# ifconfig ethX down
# ifconfig ethX hw ether NEW_MAC_ADDR
# ifconfig ethX up
但是這樣重啟後就失效了,需要再敲一遍。當然也可以寫入rc.local來解決
- 方法2:
與方法1類似,只是用ip命令代替ifconfig:
# ip link set ethX address NEW_MAC_ADDR
但是依舊重啟後失效
- 方法3:
對於RedHat系統,
# vi /etc/sysconfig/network-scripts/ifcfg-ethX
注釋掉HWADDR行,如果有的話,加入活修改:
MACADDR {NEW_MAC_ADDR}
儲存退出即可
關於HWADDR和MACADDR的區別(很容易把HWADDR誤認為是控制MAC地址的,因為ifconfig輸出時就顯示HWaddr的嘛 -.-),可以參考如何修改mac地址讓它一直生效? ,以及redhat.com.cn上面的在一個乙太網路介面設定檔中,有那些可以配置的參數? 這兩篇,摘抄一段如下:
HWADDR=, 其中 以AA:BB:CC:DD:EE:FF形式的乙太網路裝置的硬體地址.在有多個網卡裝置的機器上,這個欄位是非常有用的,它保證裝置介面被分配了正確的裝置名稱 ,而不考慮每個網卡模組被配置的載入順序.這個欄位不能和MACADDR一起使用.
MACADDR=, 其中 以AA:BB:CC:DD:EE:FF形式的乙太網路裝置的硬體地址.在有多個網卡裝置的機器上.這個欄位用於給一個介面分配一個MAC地址,覆蓋物理分配的MAC地址 . 這個欄位不能和HWADDR一起使用.
另外,還可以參考ifup指令碼中關於HWADDR和MACADDR的處理:
# remap, if the device is bound with a MAC address and not the right device num
# bail out, if the MAC does not fit
if [ -n "${HWADDR}" ]; then
FOUNDMACADDR=`get_hwaddr ${REALDEVICE}`
if [ "${FOUNDMACADDR}" != "${HWADDR}" ]; then
curdev=`ip -o link | awk -F ':' -vIGNORECASE=1 '/$HWADDR/ { print $2 }'`
rename_device "${REALDEVICE}" "${HWADDR}" "${curdev}" || {
echo $"Device ${DEVICE} has different MAC address than expected, ignoring."
exit 1
}
fi
fi
# this isn't the same as the MAC in the configuration filename. It is
# available as a configuration option in the config file, forcing the kernel
# to think an ethernet card has a different MAC address than it really has.
if [ -n "${MACADDR}" ]; then
ip link set dev ${DEVICE} address ${MACADDR}
fi
再看下nameif的man文檔:
nameif looks for the interface with the given MAC address and renames it to the name given.
就能知道HWADDR和MACADDR的不同之處了,前者是用來根據HWADDR綁定ethX名稱的,後者才是真正用來修改MAC地址的