Transferring files between outside locations and your VirtualBox VM

Generally you can exchange files between your VM and 1) other computers by network, and 2) the host computer in which the VM is running.

1) from networked computers

Within your VM you can perform any machine-to-machine file transfer method that uses networking if your VM is networked. The provided VM is nearly identical to the physical lab laptops. So I refer you to the handout you received on the first day of class, and to which there's a link on the class website, concerning how to get "networked." It works the same way in your VM.

I will assume that the host computer in which your VM runs is already networked (has an IP address) and that there exists in your LAN a dhcp server. Most home networks do run one, within the router box their ISP installed in their homes. That's where a host computer for VirtualBox would get its IP address in the first place. With the dhclient program you will need to use the right name for the interface, which in the VM is enp0s3.

Then, if for example the instruction page for my exercise contains a link to a file you are supposed to download, you can get it that way within the VM. Run the GUI, run Firefox, go to the page, click the link, download the file. Most of the files in question will also be found in /home/public on sputnik. So you could download such a file from there. For example, in a terminal or terminal window within the VM, something like:

scp .

will drop it into the VMs current working directory (that dot there above, don't forget it). The password is CS78password.

Obtaining connectivity to your host machine, and the internet

Many useful exercises can be constructed with VirtualBox strictly internally. That is, VMs can network-connect among themselves, but themselves only. They cannot talk to the internet, nor even their host machine in which they run. But if you wish, you can gain further connectivity by adding an appropriate, extra interface. The reach of a VM is a function of  its interfaces' types. VirtualBox offers 7 different types:


When you add/enable an interface to a VM you must specify what type it is by choosing one from the drop-down menu. Then, what you can and can't talk to is represented by this table:

from: VirtualBox Network Settings: Complete Guide by Michael Bose

If you have a VM in a lab exercise where it only needs to talk to other VMs, but want it to talk to the outside (for example, to facilitate file movement between it and your host in order to edit in the familiar host instead of the VM), I suggest you bestow an extra interface of "NAT Network" type upon the VM. Then when the machine runs, it can run a dhcp client on the NAT-network-type interface (automatically or manually) and will receive an address. The interface names, in linux, for the various VirtualBox interfaces, are:

VirtualBox naming becomes linux's
Adapter 1 enp0s3
Adapter 2 enp0s8
Adapter 3 enp0s9
Adapter 4 enp0s10

So in the screenshot above where it is Adapter 4 that is given NAT Network type, gaining an address on it after the computer is up and running could be done as:

dhclient  -v  enp0s10

The interface will end up, under VirtualBox default settings, with an address within the network and a suitable gateway route through (a "phantom" machine maintained by VirtualBox). This will suffice for connectivity with both the host machine and others in whatever network(s) the host machine can reach.

Above, the VM obtained address on interface enp0s10. The gateway route is visible. It pinged to, which is its host, and to, which is in the internet.

At this point file exchange with the host, or internet machines, can be done by normal file transfer methods.

A particular use the this arises when you need to edit a file within a linux VM like this. Doing so within the VM might be problematic because you don't know how to use linux character-mode editors like vi, and don't want to use an easier graphical-mode editor like gedit because graphical-mode is memory hungry and you need to economize on memory, especially if you are running multiple VMs at the same time. You could "export" such a file to a machine where you like to edit text, use your chosen tool to do so, then return the edited file to your VM. If you do that, in order to avoid possible problems, "sanitize" the file on the VM by running:

dos2unix  <filename>   if you edited the file in a Microsoft environment


mac2uninx  <filename>   if you edited the file in an Apple environment

(The reason for this is to accommodate the line termination convention differences among the platforms.)

Note that with NAT Network interfaces you can freely reach the host from the VM but not the other way around. So export files VM-to-host by initiating a "push" from the VM, and import them back by initiating a "pull" from the VM, in terms of your file transfer tool.


2) from the host computer

Other than getting a file in from a network, if you have one on the host machine you get it from there. You must enable the host-and-VM to exchange files with each other. On the VM's horizontal menu click "Devices" and on the resulting submenu "Drag and Drop." If you select "Host to Guest," you can drag a file from the host computer's file manager into a file manager in the VM. The VM does have a file manager. It can be launched within the GUI's "favorites" from the blue icon that looks like a filing cabinet.