Configure specific VM IP address using Virtualbox DHCP and VM Mac address in "Host only" network (

This is for discussing general topics about how to use VirtualBox.
Post Reply
Pelacime
Posts: 3
Joined: 19. Sep 2019, 14:03

Configure specific VM IP address using Virtualbox DHCP and VM Mac address in "Host only" network (

Post by Pelacime »

Hello,

I would like to know if it is possible to set a specific IP on a VM from the VirtualBox DHCP in a "Host only" network mode.

I know how to setup a range on the "Host only" network mode. However, the VM IP addresses that are assigned by the Virtualbox DHCP are incremental. I would like to configure them as static from the Virtualbox DHCP.

For example; I would like to force VM1 with a given MACADDR1 address to have the IP address of my choice (192.168.1.50), using the Virtualbox DHCP (and not having the incremental IP from the Virtualbox DHCP).

Code: Select all

HOST ONLY RANGE (vboxnet0): 192.168.1.0/24
HOST: 192.168.1.1
VIRTUALBOX DHCP:  192.168.1.2
LOWER ADDRESS LIMIT: 192.168.1.3
MAX ADDRESS: 192.168.1.254

VM1 (MACADDR1) : 192.168.1.50 (assigned by the Virtualbox DHCP)
VM2 (MACADDR2) : 192.168.1.60 (assigned by the Virtualbox DHCP)
So far I did not find the options or a solution that could be used from Virtualbox to establish such network addressing (DHCP reservation).

Thank you in advance for any help you may provide regarding this question.
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Configure specific VM IP address using Virtualbox DHCP and VM Mac address in "Host only" network

Post by scottgus1 »

There is a "Vboxmanage dhcpserver" command:

Code: Select all

VBoxManage dhcpserver       add|modify --netname <network_name> |
                                       --ifname <hostonly_if_name>
                            [--ip <ip_address>
                            --netmask <network_mask>
                            --lowerip <lower_ip>
                            --upperip <upper_ip>]
                            [--enable | --disable]
                            [--options [--vm <name> --nic <1-N>]
                             --id <number> [--value <string> | --remove]]
                             (multiple options allowed after --options)

VBoxManage dhcpserver       remove --netname <network_name> |
                                   --ifname <hostonly_if_name>
and usage info on section 8.39. I don't know if this does what you want, though. I would recommend opening the PDF version of your help manual (defaults to "C:\Program Files\Oracle\VirtualBox\doc\UserManual.pdf"), and searching for 'DHCP'.
Pelacime
Posts: 3
Joined: 19. Sep 2019, 14:03

Re: Configure specific VM IP address using Virtualbox DHCP and VM Mac address in "Host only" network

Post by Pelacime »

Hello,

Thank you very much for your answer. I read the section 8.39 (p193 virtualbox/6.0.12/UserManual.pdf).
Maybe I misunderstood the section, it seems to explain how to configure the DHCP server itself, not how to set up a specific IP for a given VM Mac Address (DHCP reservations).

Would you mind showing me a working command line that would automatically reserve an IP (not incremental, as mentioned above) for VM1 (with MACADDR1) please?
Last edited by Pelacime on 19. Sep 2019, 16:30, edited 2 times in total.
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Configure specific VM IP address using Virtualbox DHCP and VM Mac address in "Host only" network

Post by socratis »

I have an idea! :!:

How about setting the static IPs ... you know... statically/manually, and not mess with the DHCP server. At all?

You know, like in the good old days? When there was no DHCP server? And we'd set the IPs manually? And the person responsible would have a spreadsheet (a paper one), and each monitor on every user's desk would have a tag on the left-hand corner with the IP written on it? Oh, I miss these days... ;)

Now the serious part. Any reason why you don't want to do that from within the VM, and you want to do it from the host? You have plenty of reserved IPs to do what you want, no? That's why they're there actually, to be used as statically assigned ones.

And I'm afraid that I don't know of a VBoxManage command to do something like that. I may have an idea, but I want your thoughts on the previous question first...
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Pelacime
Posts: 3
Joined: 19. Sep 2019, 14:03

Re: Configure specific VM IP address using Virtualbox DHCP and VM Mac address in "Host only" network

Post by Pelacime »

socratis wrote:I have an idea! :!:

How about setting the static IPs ... you know... statically/manually, and not mess with the DHCP server. At all?

You know, like in the good old days? When there was no DHCP server? And we'd set the IPs manually? And the person responsible would have a spreadsheet (a paper one), and each monitor on every user's desk would have a tag on the left-hand corner with the IP written on it? Oh, I miss these days... ;)
At first I thought you were serious on that remark... And finally you made me :mrgreen:
Awesome answer, like good old days indeed!
socratis wrote: Now the serious part. Any reason why you don't want to do that from within the VM, and you want to do it from the host? You have plenty of reserved IPs to do what you want, no? That's why they're there actually, to be used as statically assigned ones.

And I'm afraid that I don't know of a VBoxManage command to do something like that. I may have an idea, but I want your thoughts on the previous question first...
To answer it simply, I have a lab on a "Host only" Virtualbox network, on which I run several vms that requires specific IP, with different systems, sometimes up, sometimes not, etc. It would be really easier in my context to handle the IP address assignation from a Virtualbox tooling itself, as for the "Host only" network configuration. I am just wondering if there is a way to perform DHCP reservations from Virtualbox by any chance.
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Configure specific VM IP address using Virtualbox DHCP and VM Mac address in "Host only" network

Post by socratis »

Pelacime wrote:At first I thought you were serious on that remark..
I actually was believe it or not... If you want static IPs, assign them statically from within your VM, case closed. I honestly used to do that, I had the log of IPs, all 200 of them in the lab. And each computer would have a sticker on them. I didn't make it up... ;)
Pelacime wrote:on which I run several vms that requires specific IP
Set them from within the VMs network preferences then. Much easier than going into each VM, getting the MAC address and assigning the MAC-to-IP someplace. One less step; getting the MAC.
Pelacime wrote: It would be really easier in my context to handle the IP address assignation from virtualbox tooling itself, as for the "Host only" network configuration
Unless you're manually creating VMs and destroying them, I see no other reason to do what was said in my previous point. And of course there's the headless VMs which is more "painful" to setup like that...
Pelacime wrote:I am just wondering if there is a way to perform DHCP reservations from virtualbox by any chance
Not straight, no. As I said I have an idea, but I'm a little bit hesitant to put it out, because 1) I don't know if it works, 2) it's completely 100% unsupported, it's a hack.

Could you be a bit more detailed on how you setup the whole thing? Are you using a bunch of VBoxManage commands to create VMs on-the-fly? And then maybe destroying them? How does the whole thing work? Do your VMs run "normal" or "headless"? The more details, the better...
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Post Reply