Why do the virtual machines and the host have different default gateways?

1

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 XP(Virtual Machine) screenshot

Windows 10 host screenshot:

Windows 10 host screenshot

Amar Kumar

Posted 2016-12-11T08:04:06.050

Reputation: 11

If you would use bridge-mode, it might be able to ping. – Tech-IO – 2016-12-11T09:59:43.763

Answers

2

Because VirtualBox assigns 10.0.2.0 network by default to its NAT network (refer to the documentation):

The virtual machine receives its network address and configuration on the private network from a DHCP server integrated into VirtualBox. The IP address thus assigned to the virtual machine is usually on a completely different network than the host. As more than one card of a virtual machine can be set up to use NAT, the first card is connected to the private network 10.0.2.0, the second card to the network 10.0.3.0 and so on. If you need to change the guest-assigned IP range for some reason, please refer to Section 9.11, “Fine-tuning the VirtualBox NAT engine”.

Also, 10.0.2.2 in your case is the interface of your host machine (another interface in addition to 192.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 machine 192.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.

techraf

Posted 2016-12-11T08:04:06.050

Reputation: 4 428

So I shouldn't be getting Request Timed out error, right? Do you know any solution for it? – Amar Kumar – 2016-12-11T08:43:47.603

I'm still not getting your answer. Updating the question with screenshots. Sorry, new here. – Amar Kumar – 2016-12-11T08:48:53.463

My answer basically states: there's nothing unusual in what you described. It's like VirtualBox developers designed their product to work. – techraf – 2016-12-11T08:50:07.947

I misunderstood "0% loss" as "0% success". You will not be able to ping your guest on NAT interface. Period. It works this way. – techraf – 2016-12-11T09:04:45.737

You can switch to NAT Network. – techraf – 2016-12-11T09:09:25.353

Yes. You rightfully noted: this is a completely unrelated topic. – techraf – 2016-12-11T09:16:32.717