Route between local machine and a VM running on remote server

5,005

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
Share:
5,005

Related videos on Youtube

bachr
Author by

bachr

Updated on September 18, 2022

Comments

  • bachr
    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
      user1089802 over 9 years
      Host only cannot be routed elsewhere. Only the host...
  • bachr
    bachr over 9 years
    There's no GUI on the remote server (it is a ubuntu server)
  • JonC
    JonC over 9 years
    You can use VBoxManage to modify the vm settings from the command line. The command should be something like ./VBoxManage modifyvm <vmName> --nic1 bridged
  • bachr
    bachr over 9 years
    I need to do specify this through the Vagrantfile and not directly with virtualbox command line
  • JonC
    JonC over 9 years
    @Arbi, I extended my answer to cover the setup in Vagrantfile.