在 VMware 虛擬機中修改 Linux 客體作業系統的 MAC 位址,常用於網路測試、授權綁定或安全實驗。本文介紹三種層級不同的修改方法:客體 OS 開機腳本、虛擬機組態檔 (.vmx) 修改、網路介面設定檔,並說明各自優缺點與適用場景。

最簡單但層級最高(OS 層級),重開機後生效,但虛擬網卡硬體位址未變。
# 在 /etc/rc.local 中加入 (exit 0 之前)
ifconfig eth0 down
ifconfig eth0 hw ether 00:0C:29:AA:BB:CC
ifconfig eth0 up
關閉虛擬機,編輯 .vmx 檔案,屬於「重新燒錄虛擬網卡 ROM」層級,永久生效且可攜帶。
ethernet0.addressType = "static"
ethernet0.address = "00:50:56:0A:0B:0C"
# 必須以 00:50:56 開頭 (VMware OUI 範圍)
ethernet0.addressType = "generated"
uuid.location = "56 4d df c1 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"
# 修改 uuid.bios 最後 6 位元組與 generatedAddress 最後 6 位元組為相同值
# 必須以 00:0C:29 開頭
適用於 RHEL/CentOS/Fedora 系列,屬 OS 層級永久設定。
vi /etc/sysconfig/network-scripts/ifcfg-eth0
# 新增或修改
MACADDR=00:0C:29:AA:BB:CC
# 重啟網路服務或重開機
systemctl restart network
/etc/network/interfaces 或 Netplan。修改後請以 ip link show eth0 或 ifconfig eth0 驗證 MAC 位址已更新。