Route between local machine and a VM running on remote server
Usually VMs in VirtualBox are added with NAT, so the VMs interface isn't directly exposed on the network. To expose it open Settings->Network and change "Attached to:" from NAT to Bridged adapter. You can then decide if you want to use DHCP or static addressing inside the VM.
Host-only Networking only provides access to the host and other VMs on the same machine, and is used when there is no need for the host's physical network interface.
To set up bridged adapter with Vagrantfile:
DHCP
Vagrant.configure("2") do |config|
config.vm.network "public_network"
end
Static IP
Vagrant.configure("2") do |config|
config.vm.network "public_network", ip: "192.168.2.205"
end
Related videos on Youtube
![bachr](https://i.stack.imgur.com/QRkom.jpg?s=256&g=1)
bachr
Updated on September 18, 2022Comments
-
bachr almost 2 years
I'm trying to establish a route between my local machine (LM) and a VirtualBox VM (VM, create with Vagrant and configured with
Host-only Networking
) running on a remote server (RS). The setup is as follows:LM (OS: Windows 7, IP: 192.168.2.8) VM (OS: Ubuntu server 14., IP: 192.168.50.4) RS (OS: Ubuntu server 14., eth0: 192.168.2.204, vboxnet0: 192.168.50.1)
I tried to add the following route to my local machine:
route add 192.168.50.0 mask 255.255.255.0 192.168.2.204
But I can only ping the second interface (i.e. 192.168.50.1) of the remote server and cannot reach the VM. How I could fix this?
-
user1089802 over 9 yearsHost only cannot be routed elsewhere. Only the host...
-
-
bachr over 9 yearsThere's no GUI on the remote server (it is a ubuntu server)
-
JonC over 9 yearsYou can use VBoxManage to modify the vm settings from the command line. The command should be something like
./VBoxManage modifyvm <vmName> --nic1 bridged
-
bachr over 9 yearsI need to do specify this through the Vagrantfile and not directly with virtualbox command line
-
JonC over 9 years@Arbi, I extended my answer to cover the setup in Vagrantfile.