I am running multiple virtual machines. I’m using VirtualBox and network setting for virtual machines is NAT.
The host machine has IP starting with 192.168.1.x and default gateway of 192.168.1.1
. While the virtual machines (Windows XP and Metasploitable2) have IP starting with 10.0.2.x
and default gateway of 10.0.2.2
.
If I run ping 192.168.1.x
(IP of Windows 10 (host)) from Windows XP, it shows that the host is up(0% loss) while if I run ping 10.0.2.x
(IP of Windows XP or Metasploitable2) from Windows10 (host) I get “Request timed out.”
Windows XP(Virtual Machine) screenshot:
Windows 10 host screenshot:
Best Answer
Because VirtualBox assigns 10.0.2.0 network by default to its NAT network (refer to the documentation):
Also,
10.0.2.2
in your case is the interface of your host machine (another interface in addition to192.168.1.x
).This is how NAT (Network Address Translation) works. VirtualBox translates the address
10.0.0.x
of your machine and sends the packets as originating from the host machine, i.e.192.168.1.x
. And it uses the same default gateway as your host machine192.168.1.1
. It does the reverse translation for packets coming back to the VM.But you will not be able to ping the guest machine using its address from
10.0.2.0
network. It's behind VirtualBox NAT router.You can configure NAT Network, or use a Bridged Adapter. But in this question you asked why they had different default gateways.