5

(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?

2
  • You should be able to reach computers in your LAN from your virtual machine but not the other way around. That is because your virtual machine usually is NAT:ed so it can reach the internet with as little effort from the user of VB as possible. So scp from your virtual to your host should work.
    – Anders
    Jan 4, 2014 at 6:29
  • your copying a file or folder. while scp what type of error did you get
    – Beginner
    Feb 28, 2014 at 6:10

3 Answers 3

7

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 [email protected] (change this to whatever the guest IP address is)

Success!

1
  • 1
    The 10.0.0.0/8 and 192.168.0.0/16 are both private nets, that are not allowed on Internet, but can reach internet with NAT. They are usually divided into subnets with subnet mask, which tells devices the first part is net address and second is host address. /8 gives first 8 bits is net, /16 first 16 bits. You usually set /24, which gives last 8 bits as host address. So for 192.168.92.1/24 net 192.168.92.0 and host 1. Highest and lowest addresses are reserved for broadcast address resp. network address. Rest can be used for hosts, in this example 192.168.92.1-.254.
    – Anders
    Jan 4, 2014 at 6:21
1

Easy way is to use scp:

Make sure you running on guest pc sshd service otherwise run below command:

/etc/init.d/sshd restart

From host PC:

scp some_host_file some_guest_user@guest_ip:~/
0

I fixed the problem by using the IP address of the second adapter in the homestead installation: 192.168.x.x in my case. Adapter 1 is NATed and shows 127.0.0.1:2222 in the output while the VM was coming up, but the actual IP address of Adapter 1 was 10.0.X.X in my case.

1
  • Welcome to AskUbuntu! Is there a way you can explain why this would work?
    – No Time
    Feb 16, 2015 at 5:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .