Can't get dhcp ip in my virtual machine on Virtual box

3

2

I have a copy of a debian virtual machine that i got from my friend. He said that all the package that required for a networking are all in there, in that virtual machine which he gave (i.e SSH package, Web server, SQL server, Mail server etc ). I tried that on my own virtual box. It's run like normal, but the problem is i alwasy got the ip of my friend dhcp ip for my virtual machine.

I got this ip for my vm.

address 10.0.2.15
netmask 255.255.255.0
gateway 10.0.2.255

i set my connection virtual machine to NAT, but it didnt change anything, but i cant connect to the internet, but the ip that i get is still the same. While computer ip for my network is (i am using wifi for this case)

address 192.168.8.100
netmask 255.255.255.0
gateway 192.168.8.1

why my virtual machine always got the last ip of my friend ip ? what could go wrong with my configuration ? I have tried to restart the network but it seems it didnt change anything like

Service networking restart/reload

or

/etc/init.d/networking restart/reload

What i expect is my vm got the ip from my network ip for example like this

address 192.168.8.101/105
netmask 255.255.255.0
gateway 192.168.8.1

Note: i can ping 8.8.8.8 through that network (address 10.0.2.15) from my vm, but i cant ping my vm through my own pc ( from the same network, i tried to ping 10.0.2.15 ) but nothing happen

gagantous

Posted 2017-12-10T20:51:11.160

Reputation: 175

Answers

3

Okay, i got the solution, i just changed my connection from NAT to Bridge/NAT network. From virtual box documentation.

NAT EXPLANATION

Network Address Translation (NAT) is the simplest way of accessing an external network from a virtual machine. Usually, it does not require any configuration on the host network and guest system. For this reason, it is the default networking mode in VirtualBox.

A virtual machine with NAT enabled acts much like a real computer that connects to the Internet through a router. The "router", in this case, is the VirtualBox networking engine, which maps traffic from and to the virtual machine transparently. In VirtualBox this router is placed between each virtual machine and the host. This separation maximizes security since by default virtual machines cannot talk to each other.

The disadvantage of NAT mode is that, much like a private network behind a router, the virtual machine is invisible and unreachable from the outside internet; you cannot run a server this way unless you set up port forwarding (described below).

BRIDGE EXPLANATION

With bridged networking, VirtualBox uses a device driver on your host system that filters data from your physical network adapter. This driver is therefore called a "net filter" driver. This allows VirtualBox to intercept data from the physical network and inject data into it, effectively creating a new network interface in software. When a guest is using such a new software interface, it looks to the host system as though the guest were physically connected to the interface using a network cable: the host can send data to the guest through that interface and receive data from it. This means that you can set up routing or bridging between the guest and the rest of your network.

And it looks like, when we setting the VM connection to NAT, it will give us a default static ip like 10.0.2.15 with gateway 10.0.2.2 based on this topic.

As i said in my question (Quoted):

I tried that on my own virtual box. It's run like normal, but the problem is i always got the ip of my friend DHCP IP for my virtual machine.

I said that the IP 10.0.2.15 is my friends previous IP, while that was incorrect since the 10.0.2.15 IP was actually a default static IP that were automatically given from VirtualBox app when you used the NAT connection for your Virtual Machine.

On the linked topic said:

In NAT mode, the guest network interface is assigned to the IPv4 range 10.0.x.0/24 by default where x corresponds to the instance of the NAT interface +2. So x is 2 when there is only one NAT instance active. In that case the guest is assigned to the address 10.0.2.15, the gateway is set to 10.0.2.2 and the name server can be found at 10.0.2.3.

gagantous

Posted 2017-12-10T20:51:11.160

Reputation: 175

1The difference is that a Bridge connection makes the VM connect to your actual (real) network. The primary router, or primary DHCP server, see's the VM as a real end device and gives the VM networking information just like it would any other device connecting to it. The NAT mode is where VirtualBox creates a virtual network and the VM pulls DHCP information from the virtual network. No other devices can ping a NAT'd VM, but they can a bridged connection. – tfrue – 2017-12-12T02:43:17.883

There are nat and nat networkinf , do these connection same ? – gagantous – 2017-12-12T04:45:01.630

No, they're not the same. – tfrue – 2017-12-12T05:42:54.403

@ChristopherJohnson So whats the difference between these type of connection? – gagantous – 2017-12-12T06:56:49.700

Read through VirtualBox documentation starting with 6.2 and it explains everything you're asking.https://www.virtualbox.org/manual/ch06.html

– tfrue – 2017-12-13T01:16:06.740

However, the difference is that with nat network, you setup a "virtual router" that hands out DHCP addresses so virtual machines on the same host can communicate with each other. – tfrue – 2017-12-13T01:17:12.400