How to set VirtualBox Ethernet Adapter to a fixed MAC address?

Discussions related to using VirtualBox on Windows hosts.
Post Reply
heqiusheng
Posts: 4
Joined: 25. Aug 2020, 02:18

How to set VirtualBox Ethernet Adapter to a fixed MAC address?

Post by heqiusheng »

How to set VirtualBox Ethernet Adapter to a fixed MAC address?
Because every time the computer is restarted, the mac address will change, causing some applications bound to the mac address to be unavailable :?:
OS info:Windows 10 x64 18363
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: How to set VirtualBox Ethernet Adapter to a fixed MAC address?

Post by mpack »

Just to clarify, what is the "VirtualBox Ethernet Adapter"? Do you mean the host only virtual adapter? (VirtualBox has many ethernet adapter simulations, but only one is visible as such on a Windows host).

If so...
heqiusheng wrote: Because every time the computer is restarted, the mac address will change
I'm pretty sure that is not the case. I too have licensed/activated software that would be upset if network MAC addresses kept changing. What makes you think this happens?
 Edit:  Plus I just checked: a reset of my PC did not change the host-only adapter MAC address. I can't find anywhere that the MAC address is configurable, so I'm assuming it's hard coded in "firmware", making it much the same as any other make of ethernet adapter. 
Rootman
Posts: 251
Joined: 1. Oct 2012, 18:29

Re: How to set VirtualBox Ethernet Adapter to a fixed MAC address?

Post by Rootman »

The MAC is defined in the VBOX file from the settings in the VM's network cards advanced configuration. It can be manually altered there. I see nowhere to tell it to change automatically. I typically use a bridged adpater, so the VMs NIC just looks like any other 'hardware' device on the network.

On a running VM I checked the MAC, it was the same as in the VBOX file. I shut it down, checked the VBOX and it was the same. I restarted the VM and checked within it (ipconfig /all) and it matched. Next I REBOOTED the VM. I checked in the VM again, same MAC. I checked the VBOX file, same MAC.

I tried changing it to HOST ONLY. Same results, the MAC stayed the same.

New MACs can be generated when cloning the VM. It's one of the options in the 'Clone Virtual Machine' dialog. Are you cloning the VM?

heqiusheng, either something in VBox that we don't know about is being done to the configuration or something from outside, some software or setting is changing the MAC. What type adapter do you have on this VM? Bridged, host only? What brand adapter? How many NICs in the guest? How many in the host? Is it a completely new NIC each time, or reverting to the same different MAC each time? Are you doing something with backing up or altering the settings with some outside software?
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: How to set VirtualBox Ethernet Adapter to a fixed MAC address?

Post by mpack »

Rootman wrote:The MAC is defined in the VBOX file from the settings in the VM's network cards advanced configuration.
The host-only ethernet adapter is a host device driver, so is not created or configured on a per-VM basis. It is unclear if this is what the OP meant.
Rootman
Posts: 251
Joined: 1. Oct 2012, 18:29

Re: How to set VirtualBox Ethernet Adapter to a fixed MAC address?

Post by Rootman »

mpack wrote:The host-only ethernet adapter is a host device driver, so is not created or configured on a per-VM basis. It is unclear if this is what the OP meant.
I'm sorry, are we talking about two different things? I changed a VM to HOST-ONLY ADAPTER from BRIDGED and the adapter type still stays the same and I can see and potentially change the MAC address in the Advanced section of the settings.

I booted to it and the IP address changed, the MAC stayed the same. When I did a 'ipconfig /all' the mac reports as exactly what's in the advanced settings of the VMs adapter.
fth0
Volunteer
Posts: 5690
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: How to set VirtualBox Ethernet Adapter to a fixed MAC address?

Post by fth0 »

Rootman wrote:I'm sorry, are we talking about two different things?
Yes, I think so. You are talking about the virtual network adapter that is provided to the guest, and mpack is talking about the virtual network adapter that is created in the host OS. Both are connected inside VirtualBox over a virtual switch, both have an IP address in the 192.168.56.x/24 range by default, and both have an individual MAC address. You can configure the MAC address of "your adapter", but VirtualBox automatically chooses a random the MAC address for "mpack's adapter", and the latter is not configurable according to the VirtualBox source code.

Edit: Corrected my mistake above.
Last edited by fth0 on 12. Sep 2020, 18:37, edited 1 time in total.
Rootman
Posts: 251
Joined: 1. Oct 2012, 18:29

Re: How to set VirtualBox Ethernet Adapter to a fixed MAC address?

Post by Rootman »

Ah, gotcha. I knew there was something I was misunderstanding.
heqiusheng
Posts: 4
Joined: 25. Aug 2020, 02:18

Re: How to set VirtualBox Ethernet Adapter to a fixed MAC address?

Post by heqiusheng »

VirtualBox Ethernet Adapter refers to the virtual network card VirtualBox Host-Only Network in the control panel, not the network card in the VM host. Restart also refers to the host restart, not the VM host restart. Before the last restart, the MAC address was 0A0027000011 and it became 0A0027000014 after the restart.
So I feel very strange. I don’t know what caused the MAC address to change.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: How to set VirtualBox Ethernet Adapter to a fixed MAC address?

Post by mpack »

Rootman wrote: I'm sorry, are we talking about two different things?
On any Windows host with VirtualBox installed, open an administrator command console and type the command "ipconfig /all". This will describe all of the network cards in your system. One of them will look like this:
IPConfig.PNG
IPConfig.PNG (16.2 KiB) Viewed 5611 times
This is the fake ethernet card that VirtualBox installs on the host, to allow the host to participate in host-only networks. I believe that this is what the OP was talking about. The MAC address in this card is not configurable, and I've never noticed that it changes either. It would be interesting for others to report what MAC theirs is using. FTH suggested a random number, but I would expect that number to be stored in the registry, and I couldn't find it (but if so, then use of a "registry cleaner" snake oil product could cause this number to be lost). Alternatively the number may be hard coded in the source code, I have not looked. But if we all have the same number then that would prove that. Heqiusheng is saying that the MAC on this card is not the same for all of us (looks like only the lsbyte differs), and it sometimes changes somehow on a host reset, which I have not observed yet.
heqiusheng
Posts: 4
Joined: 25. Aug 2020, 02:18

Re: How to set VirtualBox Ethernet Adapter to a fixed MAC address?

Post by heqiusheng »

mpack wrote:Heqiusheng is saying that the MAC on this card is not the same for all of us (looks like only the lsbyte differs), and it sometimes changes somehow on a host reset, which I have not observed yet.
Yes as you said
Okay, I don’t care for the time being, after all, the impact is not great
Last edited by mpack on 26. Aug 2020, 09:49, edited 1 time in total.
Reason: Trim size of quoted text.
fth0
Volunteer
Posts: 5690
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: How to set VirtualBox Ethernet Adapter to a fixed MAC address?

Post by fth0 »

mpack wrote:FTH suggested a random number
Yes, and I stand corrected now regarding Windows hosts.

Here comes the path to follow to the truth: ;)

In the Global Settings folder, you can find a file named HostInterfaceNetworking-vboxnet0-Dhcpd.log (or similar), containing a log message similar to

Code: Select all

MAC address is not specified: will use generated MAC 08:00:27:[...]
In the VirtualBox source code (*), you can find this message in

Code: Select all

https://github.com/mdaniel/virtualbox-org-svn-vbox-trunk/blob/master/src/VBox/NetworkServices/Dhcpd/Config.cpp#L283
In line 266, there is a tell-tale comment

Code: Select all

/** @todo the MAC address is always generated, no XML config option for it ... */
If you follow the call to RTUuidCreate() in line 273 (e.g. in your own copy of the source code), you'll reach either generic code using a random number generator, or Windows specific code that I didn't bother to follow along yet, hence my mistake. (Perhaps I'll amend this post later on ...)

On Windows hosts, the MAC addresses (as posted in this thread) are obviously not random.

On my macOS host, the Host-Only interface is created with a random MAC address, when the first VM using it is started, and it keeps existing up to the next macOS shutdown or restart.[/s]


(*) I deliberately use this non-official source repository, because I'm able to use line numbers in URLs with it. Is there a way to use line numbers in URLs pointing to the official source repository?


Edit: I've been on the wrong track, confusing the virtual DHCP server with the VirtualBox Host-Only interface.
Last edited by fth0 on 12. Sep 2020, 18:44, edited 2 times in total.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: How to set VirtualBox Ethernet Adapter to a fixed MAC address?

Post by mpack »

fth0 wrote: In the Global Settings folder, you can find a file named HostInterfaceNetworking-vboxnet0-Dhcpd.log (or similar), containing a log message similar to
I saw that log, unfortunately the MAC address it says it generated is not what ipconfig showed the card to actually be using, which left me at a loss. Perhaps the log is only generated when a VM uses the host-only network, which is not something I typically use (I typically would use Bridged).

I also couldn't see the MAC address being configured in VirtualBox.xml - I guess the source code comment confirms that I didn't just overlook it.
fth0
Volunteer
Posts: 5690
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: How to set VirtualBox Ethernet Adapter to a fixed MAC address?

Post by fth0 »

I'm still quite wrong myself, sorry for the confusion I'm creating. I've confused the source code of the virtual DHCP server with that of the Host-Only interface. I'll investigate further, before I keep writing nonsense ...
heqiusheng
Posts: 4
Joined: 25. Aug 2020, 02:18

Re: How to set VirtualBox Ethernet Adapter to a fixed MAC address?

Post by heqiusheng »

I just restarted the system and found that the MAC address has not changed this time, the same as before the restart. Um...it's weird
Well, since there is no change, then everything will be fine. Thank you for your patience. Everyone is so enthusiastic. I didn’t expect it.
Thanks again :D
fth0
Volunteer
Posts: 5690
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: How to set VirtualBox Ethernet Adapter to a fixed MAC address?

Post by fth0 »

Because I was really embarrassed (trying to be as exact as I can), I've been investigating further, to finally discover the following:

On a Linux host, VirtualBox Host-Only adapters are automatically named vboxnet<i> (i = 0, 1, ..., 127), and assigned the MAC address 0A:00:27:00:00:<i> (VBoxNetAdp.c).

On a Windows host, each VirtualBox Host-Only adapter is assigned an interface index (IfIndex) by the Windows network stack. VirtualBox then assigns the MAC address 0A:00:27:<IfIndex> to the adapter (VBoxNetAdp-win.cpp).

According to MSFT_NetAdapter class, the "index value may change when a network adapter is disabled and then enabled, and should not be considered persistent". This could be the cause of the changing MAC address in the OP's scenario.
Post Reply