Connect two VirtualBox VMs with a hardware machine with a single public IP

2

I have a hardware machine running Ubuntu 12.04 and a Selenium server hub connected to the internet through a public IP. On that machine I'm running two VirtualBox VMs running Selenium server nodes and a web server. The communication between the hub and the nodes needs to be bidirectional therefore VMs need to have the network connection set to bridge. But that doesn't work because I only have a single public IP.

Is there a way to make a virtual LAN between the VMs and the hardware machine so I can access the the virtualized web servers and Selenium servers from the hardware machine?

lucassp

Posted 2013-10-24T10:51:47.510

Reputation: 153

Answers

1

Yes there is. Kinda. It is a bit less straightforward than in VMWare, but there is.

I am not sure whether you want the two guests to be able to talk to each other. If you do, you will find here a good guide to achieve that. Also, to have access to your VMs, you shall have to enable port-forwarding on the host machine. Again, you will find here the relevant guide. Once you know what to look for, you will discover that these are but two of very many excellent guides you can find out there.

MariusMatutiae

Posted 2013-10-24T10:51:47.510

Reputation: 41 321

Thanks! Now I have another issue. I am able to select Host-only Adapter but the Name: select box doesn't have any values in it. And it seems I need to select an interface to attach to. – lucassp – 2013-10-24T12:21:08.093

Nevermind, found it. – lucassp – 2013-10-24T12:28:58.453

@lucassp Also, you should remember that you can always reach machine behind NATs by means of "reverse ssh tunnels". There are lots of guides on Google on how to do it. My extra advice is to use a utility called autossh which restarts automatically if the connection is interrupted. The configuration on server and client are two one-liners, pretty simple. – MariusMatutiae – 2013-10-24T13:50:27.553

It seems I have another problem: the Selenium server nodes connect correctly to the Selenium server hub on the Host machine, but the Selenium server hub always tries to check the availability of the nodes using the NAT IP 10.0.0.x, and it fails, of course. If I disable NAT, everything is fine but I don't have internet on the VMs anymore. Any idea on how to fix it? – lucassp – 2013-10-24T14:14:22.530

Add another adapter to the VMs? One with Nat, one without? – MariusMatutiae – 2013-10-24T14:20:07.280

That's the problem. If I have two adapters on each VM one NAT (10.0.0.x) and Host only (192.168.56.x), and on each VM a Selenium server node connects to the Selenium server hub of the host machine (192.168.56.1), then the Selenium server hub on the host machine tries to check the nodes periodically using 10.0.0.x IPs and not using the local Host only network IPs. Therefore I need to disable NAT and lose my internet connection, and I still need it. – lucassp – 2013-10-24T14:33:16.840

Do you have access to the hub? I.e., something like telnet or ssh? – MariusMatutiae – 2013-10-24T14:44:32.573

The Hub runs on the Host machine and can be accessed using the "Host only" at 192.168.56.1. It looks like it's a Selenium issue: the nodes register themselves to the hub using the NAT IPs and not the "Host only" IPs. I will do some more tests tomorrow. http://stackoverflow.com/questions/13625153/not-able-to-register-selenium-webdriver-node-on-vm-to-the-hub-on-host

– lucassp – 2013-10-24T14:52:23.257

Add a route in its routing table. – MariusMatutiae – 2013-10-24T14:56:10.457

1

The error you have right now, is that the Guest is able to talk up to the Host, but is registering the wrong ip address for the callback. By using localhost / 127.0.0.1, you can tell Selenium node and grid instances to rely on local port forwarding.

Configure the Guest VM to use NAT Networking, and add a Port Forwarding for port 5555, and port 4444, leaving both ip addresses blank or set to 0.0.0.0 You may also want to forward port 80, so that your Host can see the Guest web server. When using NAT, in the Guest machine, the ip address 10.0.2.2 is the ip address to talk to the Host machine. Here are the commands:

Host Machine, as Hub

java -jar selenium-server-standalone.jar -role hub -port 4444

Guest Machine, as Node

java -jar selenium-server-standalone.jar -role node -host 127.0.0.1 -port 5555 -hub http://10.0.2.2:4444/grid/register

If you want multiple VM machines to communicate to each other, setup each of them with a secondary network connection, set to "Internal Network", named "vboxnet0" or similar. Then give each of them a static ip address, ex: 192.168.1.10 (machine 1) and 192.168.1.11 (machine 2).

Apollo Clark

Posted 2013-10-24T10:51:47.510

Reputation: 111