Page 1 of 1

How to connect guest to router over bridge via headless virtual box

Posted: 23. Sep 2020, 19:45
by programmerskitchen
Hello,

I'm trying to connect a guest running on an headless Ubuntu 20 directly to the router (over bridged networking) so it looks like an own device from the router. I did this several times with a GUI but don't know how to do it with with the command line/vboxmanage. For example if my router's IP adress is 192.168.1.2 and host 192.168.1.3, the VM's guest IP would be 192.168.1.4.

I've found some tutorials on how to create a network bridge but I'm not sure which one does the trick.
In the first one an interface is added to the host by

Code: Select all

brctl addbr vmtestbr1 
and afterwards set for the guest. While in the other tutorial

Code: Select all

VBoxManage modifyvm VM1 --nic1 bridged --bridgeadapter1 eth0
is used for NIC1 of the guest.
So if I understand correctly I would need to change the network settings within the guest OS (after adding the brideadapter) for latter method but would have an IP as 192.168.1.4 afterwards. Is there any way to achieve this without changing the network settings from within the guest's OS?

My main goal is to make the guest reachable from the LAN or outside the host.



Thanks
Alex

Re: How to connect guest to router over bridge via headless virtual box

Posted: 23. Sep 2020, 20:00
by scottgus1
You're posting in Windows Hosts, but:
programmerskitchen wrote:a guest running on an headless Ubuntu 20
Is the host Windows or Ubuntu?

No 'brctl bridge' stuff or other such inside the host or guest OS is necessary for Virtualbox Bridged to work. (Only caveat is, Virtualbox Bridged does not always work with Wi-fi.)

It appears you are combining commands in an unsupported manner:
programmerskitchen wrote:VBoxManage modifyvm VM1 --nic1 bridged --bridgeadapter1 eth0
The commands are:
VBoxManage modifyvm "vmname" --nic<1-N> none|null|nat|natnetwork|bridged|intnet|hostonly|generic

VBoxManage modifyvm "vmname" --bridgeadapter<1-N> none|<devicename>


The first would set the guest to Bridged:
VBoxManage modifyvm VM1 --nic1 bridged

The second connects the Bridged adapter to the host device:
VBoxManage modifyvm VM1 --bridgeadapter1 eth0

If you want the guest to have a fixed IP address you will have to set this up inside the guest OS. OS's typically are set to look for an IP address on DHCP. As best I know, Virtualbox has no method to force an IP address. (It may also be possible to control what IP address the guest OS receives from DHCP in the router you're using, by setting something up against the guest's MAC address, which is known in the guest's Network card settings.)

Re: How to connect guest to router over bridge via headless virtual box

Posted: 23. Sep 2020, 20:47
by programmerskitchen
Thanks for your answer, the host is an Ubuntu 20 LTS while the guest is a linux machine with enabled DHCP. Actually I don't need a fix IP addressas I just want it to be accesible from outside the host.


So I basically just need to:

1. Set the guest to bridge mode with vboxmanage
2. Connect the bridged adapter to the host device

Re: How to connect guest to router over bridge via headless virtual box

Posted: 23. Sep 2020, 20:55
by scottgus1
programmerskitchen wrote:host is an Ubuntu 20 LTS
Moving to Linux Hosts.

Re: How to connect guest to router over bridge via headless virtual box

Posted: 23. Sep 2020, 20:56
by scottgus1
If 1 and 2 are the posted commands, then yes.

Re: How to connect guest to router over bridge via headless virtual box

Posted: 24. Sep 2020, 18:25
by programmerskitchen
Thank you very much, it worked without any issues :)

Re: How to connect guest to router over bridge via headless virtual box

Posted: 24. Sep 2020, 19:03
by scottgus1
Great! Glad you're up and running.