Virtual machine, after changing MAC address of eth0, the connection does not work. When changing only the last three octets, the situation is the same. Restarting the modem does not give results, there is no filtering by MAC addresses. Why is this happening and how can I fix it?
VirtualBox does not support changing the MAC address inside the guest virtual machine.
The “official” method of operation is to change the address in the virtual machine settings when the guest computer is completely turned off.
Guest MAC address information is generated by the physical hardware, in this case the VirtualBox network adapter.
VirtualBox uses the hardware on the host and provides the MAC address for the guest as if it were in metal. But a reasonable question arises, because on a physical computer, the MAC address is also hard-coded into the network card and it is impossible to change it on it, but Linux supports changing the MAC address to arbitrary ones and the network is working fine, why is there such a difference?
And by the way, changing the MAC address in the virtual machine breaks the Internet connection for the wired interface only. For Wi-Fi wireless network interfaces (connected via USB), changing the MAC address does not lead to any problems, they work fine, there is a network connection.
There are two possible reasons for this behavior:
1. Whatever MAC address is hard-coded into the network card, the final decision whether or not to accept a packet is made by the operating system kernel. This is in the case of a physical computer. In the case of a virtual machine, it is up to VirtualBox, which may not be aware of what exactly is happening in the virtual machine and that it has changed its MAC address. Therefore VirtualBox does not know about the new MAC address and does not forward Ethernet frames to it.
2. The differences between wired and wireless networks are obvious: in wireless networks, radio waves propagate freely and every device within reach has access to absolutely all transmitted frames. As for the wired network, the sender sends Ethernet frames to a specific port (in the sense of the device's network port). That is, it is possible that the data is simply not sent by the sender to the new MAC address, since it does not know anything about it.
However, some users wrote that they managed to get the wired interface in the virtual machine to work after changing the MAC address - for this they put it in promiscuous mode. This method did not work for me (the network is still unavailable), but you can try it yourself (replace the eth0 interface name with your own):
sudo macchanger -s eth0 # check the current MAC address sudo macchanger -r eth0 # change the MAC address to random sudo ip link set dev eth0 promisc on # put the network interface in promiscuous mode ping 126.96.36.199 # check if the network is working # sudo macchanger -p eth0 # return the old MAC address if the network is down
As for the wireless interfaces in the virtual machine, everything works there without the need to switch the network interface to promiscuous mode.
Commands for changing the MAC-address of the Wi-Fi card (replace the wlan0 interface name with your own):
sudo ip link set dev wlan0 down # this is required sudo macchanger -s wlan0 # check the current MAC address sudo macchanger -r wlan0 # change the MAC address to random sudo ip link set dev wlan0 up # this is required # sudo macchanger -p wlan0 # if needed, return the old MAC address