Change VirtualBox DHCP to issue 192.168.x.x adresses instead of 10.0.x.x adresses?

31

6

I have a VirtualBox (v4.1.8) VM that is automatically assigned with an IP in the 10.0.x.x range via DHCP.

Can I change it to use the 192.168.x.x range instead?

Boy Baukema

Posted 2012-03-08T13:37:56.353

Reputation: 412

This is a perfectly valid question as i.e. having your VM run at 10/8 will conflict if you want to connect to a company VPN, which usually grabs the 10/8 range as well. – mmlac – 2019-01-23T11:58:06.033

2Could someone enlighten me as to why I'm getting a downvote? It may be a beginner question, but I am a beginner with VirtualBox and I had to google a fair bit to get to the answer, which is:

VBoxManage modifyvm "NameOfVM" --natnet1 "192.168/16"
 – Boy Baukema  – 2012-03-08T13:43:49.687

I can't, not enough rep, have to wait a day... if you could post it I could accept and the next guy will have an easier time :). – Boy Baukema – 2012-03-08T13:46:09.697

In fairness I was looking for this feature a year or so ago - the specific answer wasn't immediately available. A bit unfair to downvote, especially without comment. – Coops – 2012-03-08T13:47:32.973

If people do not choose to leave a reason as to their downvote they we can't make them. – None – 2012-03-08T14:10:55.883

4It's a tradeoff...encouraging feedback through voting, or require reasons and questions don't get downvotes. Personally I think it's a little rude not to leave a reason, as it doesn't enlighten users to better hone question skills or ask questions appropriate to the community, but that's my opinion. – Bart Silverstrim – 2012-03-08T14:14:25.403

1May be those who downvoted were questioning the fact this DHCP address was conflicting with your intranet assuming there should be no routing but NAT between the latter and the internal network used by VirtualBox. – jlliagre – 2012-03-08T15:00:33.363

My problem turned out to be I need to add a host network adapter before I could access the VM. I'd worked too much with VMWare fusion and just assumed I would access the VM (with SSH) from my host. So any downvotes for me looking in the wrong direction were deserved.... – Boy Baukema – 2012-03-09T09:04:16.183

You actually don't need to add a host network adapter to access the VM. – jlliagre – 2012-03-11T21:45:25.260

Answers

23

Thanks to @RelaXNow, here is the answer to the question:

VBoxManage modifyvm  "NameOfVM" --natnet1 "192.168/16" 

cutrightjm

Posted 2012-03-08T13:37:56.353

Reputation: 3 966

After changing the DHCP settings, the DHCP server still offered leases in the old IP range to the guest. I had to restart the VirtualBox drivers to get the changes to take effect, using sudo vboxreload on the host (VirtualBox 5.1.26). – Rob W – 2017-08-27T15:56:41.553

2Which should be ran on the host machine, not the VM (it wasn't obvious to me from the start) – periklis – 2014-01-30T11:50:28.243

16

Providing I have understood the question, if you check chapter 6 of the manual it says:

In the VirtualBox graphical user interface, you can configure all these items in the global settings via "File" -> "Settings" -> "Network", which lists all host-only networks which are presently in use. Click on the network name and then on the "Edit" button to the right, and you can modify the adapter and DHCP settings.

enter image description here

tombull89

Posted 2012-03-08T13:37:56.353

Reputation: 6 533

Recent versions have it File -> Preferences -> ... – Jari Turkia – 2018-03-13T13:33:56.707

-1, OP's issue isn't the Host Network but the NAT. – mmlac – 2019-01-23T11:59:44.133

Good answer thanks for the pic, I read the doc too, but I kept going to the specific machine settings not the "general" settings! – SSH This – 2013-01-18T17:50:53.223

3

Yes it can be changed. There is documentation on it here:

http://www.virtualbox.org/manual/ch08.html#vboxmanage-dhcpserver

It's handled through the VBoxManage dhcpserver command.

Coops

Posted 2012-03-08T13:37:56.353

Reputation: 201

3

You usually don't need to modify VirtualBox DHCP address range. This network is internal and only exists between your VM and the VirtualBox application. There is no routing involved but just NAT.

Should you want to allow accessing your virtual machine from the outside while staying in the default NAT mode, it is possible to selectively open ports (port forwarding).

For example, to allow access to your internal ssh server through the 2022 port, use this command:

VBoxManage modifyvm "NameOfVM" --natpf1 "guestssh,tcp,,2022,,22"

jlliagre

Posted 2012-03-08T13:37:56.353

Reputation: 12 469

Yes, but weird things can happen if your host doesn't know how to route to the VM. I had this problem with Vagrant taking 5 minutes to mount the shared folder. I could ping google from the VM, but I couldn't ping anything on the local net. – rox0r – 2013-10-17T02:37:34.220

@rox0r I don't get what you mean. There is no routing involved from the host to the VM when NAT is used. From the outside, the VM is simply using the host address. – jlliagre – 2013-10-17T04:11:36.280

1Yeah, but the VM will not route back out the default gateway if it thinks the destination is on its subnet. Ie: if the VM is 10.0.2.15/24 and you try to ping 10.0.2.10 which is on the Host's subnet, it will not try to route through the NAT gateway. The same is true if you involve port-forwarding and the connecting machine is 10.0.2.10. The packages will route to the VM but they'll never route back out. – rox0r – 2013-10-17T22:03:58.783

Got it. Having the same subnet both internally and externally would be a very bogus configuration indeed. – jlliagre – 2013-10-18T09:29:05.987