Ubuntu – Setting up a network between a host and guest virtual machine

networkingscpservervirtualbox

(I'm running ubuntu server 12.04 on virtual box)

I'm trying to transfer a file (scp) from my laptop to one of the directories of a virtual machine. I tried sharing folders, but that failed. I'm a bit of a networking newbie.

I've looked at like 20-30 pages. Here's one:
http://www.howtoforge.com/moving-files-between-linux-systems-with-scp

I followed those steps exactly. My problem is that when I try using scp, it just hangs. I'm also not sure which network interface to configure (eth0, eth1?) in the guest OS. Another (significant?) detail is that the inet address of eth0 is 10.0.2.15 instead of something like 192.168.x.y.

I've enabled the bridge adapter and the host-only adapter. Both the laptop and guest VM have openssh-server installed. I'm not sure what to do at this point.

Is there a better place to ask about this?

Best Answer

The reason you're not able to scp/ssh is your Guest and Host machines are currently on separate networks. The Guest machine is currently NAT'd to the host network so that it may access the internet. Essentially you'll want to set up another network adapter on the Guest VM.

It should also be noted that the 10.0.2.* subnet is local to your VBox config and is the NAT'd address of the machine. Do not disable this device. The 192.168.. subnet is IP space allocated for internal/personal networks.

To do this:

  1. Shut down Guest VM
  2. In VBox preferences, select Network and "Adapter 2." Enable it and set "Attached-to" to "Host-Only Adapter"
  3. Power on Guest VM. Run the following command:
$ sudo ifconfig eth1

Link encap:Ethernet HWaddr XX:XX:XX:XX:XX:XX inet addr:192.168.56.101 Bcast:192.168.56.255 Mask:255.255.255.0 inet6 addr: XXXX::XXXX:XXXX:XXXX:XXXX/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:296 errors:0 dropped:0 overruns:0 frame:0 TX packets:237 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:32116 (31.3 KiB) TX bytes:37642 (36.7 KiB)

Now you'll need to edit /etc/network/interfaces. Change the address to your base IP address.

auto eth1
iface eth1 inet static
address 192.168.56.101
netmask 255.255.255.0

You should now be able to ssh/scp back and forth between your host and guest machine using the correct IP addresses. (Note, it will not be the IP from eth0)

From the host machine to guest machine:

$ ssh user@192.168.56.101 (change this to whatever the guest IP address is)

Success!