I’ve been using VMware Fusion on my Mac but it costs about $60. Not that much but Virtualbox is free, so I also have Virtualbox as well.
For my VMs I use DHCP and this has caused some problems but mainly on Virtualbox. With VMware Fusion (and VMware Workstation) everything works fine.
VMware
With VMware, under “Edit Hardware Settings” then “Network Adaptor” I just set the network
Mac: “Share with MAC”
PC: NAT
This causes the system to act as a router, isolating the VM’s on their own network, while allowing internet connectivity outbound as well as being able to connect to the VMs from my laptop and being able to connect from one VM to another.
VirtualBox
Bridge Adaptor – my typical default, doesn’t work when not connected to the network (like when wifi is off or flaky)
Host-Only Adapter – works on laptop, but cannot connect to outside network
Nat Network Adaptor – works with or without network connection but requires port forwarding
Bridge adaptor is the easiest and works when you are connected to the network. It doesn’t work when you are off the network or the network is a wifi and spotty.
In that case you can use “Host-Only Adaptor” which does work when you are off the network, but once you are back on the network and want the VMs to connect to the outside network you can’t.
The best of both worlds is “Nat Network Adaptor“. The problem with Nat Network Adaptor is you have to set up a Nat Network Adaptor and set up port forwarding rules.
Create a NAT Network
click menu “VirtualBox -> Preference” then “Network”
Click button “Nat Network”
Click box with + sign on right to create a Nat Network
Click the screwdriver to the right
Keep the default Nat Network name or customize
Make sure “Supports DHCP” is checked
Click “Port Forwarding”
Under port forwarding you add your rules on how to talk to your VMs.
For example I have a VM called “Linux Target” with an IP of 10.0.2.6
I’ll add a rule to allow me to SSH to this VM. SSH is on port 22.
I’ll give the rule a meaningful name for me. In my case “SSH to Linux Target”
I’ll be using my local host for Host IP, so I give it 127.0.0.1
I’ll pick out a safe but meaningful port on my local host that will forward to my VM’s port 22. I pick out local host port 2022 and map that to my VM’s port 22 on 10.0.2.6.
The rule will look like the last line in the following table:
In the above table I’ve added rules for both HTTP connections over port 1080 which my web application on the VM uses and SSH connections over port 22 which SSH uses for 3 VMs on my laptop.
Now the trick is, in order to connect to the VM from the laptop, I don’t use the VM’s name or IP. I use the name “localhost” specify the local host port that is forwarded to my VM. For example to ssh to “Linux Target” I would use
ssh -p 2022 localhost
and to connect to HTTP on “Linux Target”, in a browser I would type
http://localhost:2080
(to connect from one VM to the other VM use the actual IP address)
Thanks to Adam Bowen for stepping me through these options. See his post at Delphix on the subject at https://community.delphix.com/delphix/topics/basic-virtualbox-networking-setup-for-landshark-2-x
Comments