network & sharing in virtualbox - full tutorial

13
U p d a t e d : N o v e m b e r 2 6 , 2 0 0 9 T h i s i s t h e f o u r t h a r t i c l e o n V i r t u a l B o x m a n a g e m e n t . T o d a y , I ' m g o i n g t o t e a c h y o u e v e r y t h i n g y o u n e e d t o k n o w o f V i r t u a l B o x n e t w o r k i n g a n d s h a r i n g . I ' m g o i n g t o s h o w y o u t h r e e d i f f e r e n t m e t h o d s o f c o n f i g u r i n g y o u r v i r t u a l m a c h i n e s a n d t h r e e d i f f e r e n t w a y s o f s h a r i n g d a t a b e t w e e n t h e h o s t m a c h i n e a n d t h e v i r t u a l m a c h i n e . A f t e r m a s t e r i n g t h i s t u t o r i a l , y o u w i l l k n o w a l l t h e r e i s t o k n o w a b o u t u s i n g V i r t u a l B o x w i t h f u n a n d c o n f i d e n c e . F o l l o w m e . I n t r o d u c t i o n F o r m o r e d e t a i l s , y o u s h o u l d r e a d t h e f o l l o w i n g a r t i c l e s . T h e y w i l l p r o v i d e y o u w i t h t h e n e c e s s a r y b a c k g r o u n d t o f o l l o w i n g t o d a y ' s m a t e r i a l w i t h e a s e a n d p l e a s u r e : H o w t o i n s t a l l V i r t u a l B o x G u e s t A d d i t i o n s - T u t o r i a l V i r t u a l B o x 3 i s a m a z i n g ! V i r t u a l B o x 3 C o m p i z s l i d e s h o w D i r e c t X i n V i r t u a l B o x 3 - P u r e j o y i s h e r e L i k e w i s e , y o u s h o u l d r e a d t h e f i r s t t h r e e i n s t a l l m e n t s o f t h i s s e r i e s : H o w t o c l o n e d i s k s i n V i r t u a l B o x - T u t o r i a l H o w t o a d d h a r d d i s k s i n V i r t u a l B o x - T u t o r i a l H o w t o e x p a n d / s h r i n k d i s k s i n V i r t u a l B o x - T u t o r i a l N o w , l e t u s b e g i n . V i r t u a l B o x n e t w o r k o p t i o n s F o r a n y o f y o u r i n s t a l l e d v i r t u a l m a c h i n e s , c l i c k o n S e t t i n g s > N e t w o r k . H e r e t h e f u n The Betrayed, Igor Ljubuncic's epic fantasy novel is available in stores! G e t E - b o o k e d i t i o n B u y f r o m C r e a t e S p a c e A d v e r t i s e ! W o u l d y o u i k e t o a d v e r t i s e y o u r p r o d u c t / s i t e o n D e d o m e d o ? R e a d m o r e D o n a t e t o D e d o i m e d o ! D o y o u w a n t t o h e l p m e t a k e e a r l y r e t i r e m e n t ? H o w a b o u t d o n a t n g s o m e d i n e r o t o D e d o m e d o ? R e a d m o r e N e t w o r k & s h a r i n g i n V i r t u a l B o x - F u l l t u t o r i a l S o f t w a r e & s e c u r i t y C o m p u t e r g a m e s L i f e t o p i c s H i l l b i l l y p h y s i c s G r e a t e s t s i t e s 3 D a r t M o d e l p l a n e s

Upload: jojokalathil

Post on 01-Nov-2014

36 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Network & Sharing in VirtualBox - Full Tutorial

Updated: November 26, 2009

This is the fourth article on VirtualBox management. Today, I'm going to teach youeverything you need to know of VirtualBox networking and sharing.

I'm going to show you three different methods of configuring your virtual machines andthree different ways of sharing data between the host machine and the virtual machine.After mastering this tutorial, you will know all there is to know about using VirtualBox withfun and confidence. Follow me.

Introduction

For more details, you should read the following articles. They will provide you with thenecessary background to following today's material with ease and pleasure:

How to install VirtualBox Guest Additions - Tutorial

VirtualBox 3 is amazing!

VirtualBox 3 Compiz slideshow

DirectX in VirtualBox 3 - Pure joy is here

Likewise, you should read the first three installments of this series:

How to clone disks in VirtualBox - Tutorial

How to add hard disks in VirtualBox - Tutorial

How to expand/shrink disks in VirtualBox - Tutorial

Now, let us begin.

VirtualBox network options

For any of your installed virtual machines, click on Settings > Network. Here the fun

The Betrayed, IgorLjubuncic's epicfantasy novel is

available in stores!

Get E-book edition

Buy from CreateSpace

Advertise!

Would you like toadvertise yourproduct/site onDedoimedo?

Read more

Donate toDedoimedo!

Do you want tohelp me take earlyretirement? Howabout donatingsome dinero toDedoimedo?

Read more

Network & sharing in VirtualBox - Full tutorial

Software & security Computer games Life topics Hillbilly physics Greatest sites 3D art Model planes

Page 2: Network & Sharing in VirtualBox - Full Tutorial

begins. This is the default view. Any virtual machine can have up to four network adapters.You can enable them selectively as you see fit. Most people will require just one.

Adapter Type defines the virtualized hardware that VirtualBox will expose to your virtualmachine. If you have a problem with one of the Adapter types, you can try another. PCnet-FAST III is the default selection.

You also have PCnet-FAST II for older machines and three types of Intel PRO/1000 cards,including two Server versions, which should be useful for people running VirtualBox in aproduction environment. For home users, the choice is rather transparent.

The most interesting part is Attached to: section. This category defines how your networkadapter will interface with existing physical hardware. Different setups will result inmarkedly different results.

Network types

We have four options here: NAT (default), Bridged, Internal network, and Host Only. Ofcourse, Not attached is also a type, but not one we can really use, per se.

Network Address Translation (NAT)

NAT means the virtual machines will have private IP addresses that are not routable fromoutside.

Example: Your host is 192.168.1.1. The VirtualBox NAT device will be marked as 10.0.2.1.Therefore, the virtual machines will be given any address in the 10.0.2.x range. Since thereis nothing to route access to machines in the 10.0.2.x/24 subnet, they will be inaccessiblefrom your host.

Page 3: Network & Sharing in VirtualBox - Full Tutorial

This setup is useful when you don't really care what IP addresses your guests have, eachone to its own. However, it is not good if you require forwarding or if you need to exposeservices to the external world. Likewise, this setup is not good for sharing via networkaccess.

Pluses: simplicity & seclusion.

Minuses: no route to virtual machines, no network sharing.

Bridged Adapter

Bridged Adapter means that any virtual machine running will try to obtain an IP addressfrom the same source your currently active, default network address got its IP address.Hence the term bridged, as the two are connected.

Page 4: Network & Sharing in VirtualBox - Full Tutorial

If you have more than one active network device, you can choose which one you want tobridge with VirtualBox. In our case, we will use the Wireless adapter wlan0.

Example: Your host has leased an address of 192.168.1.100 from the router. The virtualmachine leases an address of 192.168.1.103 from the router. The two machines now sharethe same network and all standard rules apply. For all practical purposes, the virtualmachine is another IP address on your LAN.

More closely, the host:

Page 5: Network & Sharing in VirtualBox - Full Tutorial

And the guest:

This setup cannot work if your device (switch, router, ISP, etc) does not permit you tolease more than one IP address. Therefore, computers with direct Internet access may notbe able to use Bridged networking.

Pluses: Allows flexible management of the network with port forwarding and servicesenabled. Allows network sharing in the classic way.

Minuses: Might not work with direct Internet access (requires router), more difficult tounderstand for new users, exposes machines to network with possible securityimplications.

Host-only Adapter

Host-only Adapter is very interesting. It's very similar to Bridged Adapter, except that isuses a dedicated network device, called vboxnet0, to lease IP addresses.

Page 6: Network & Sharing in VirtualBox - Full Tutorial

Your host machine is the de-facto VirtualBox router, with the IP address of 192.168.56.1.The adapter is not in use if there are no virtual machines running with Host-only setup.However, once they come up, this adapter serves IP addresses to the virtual machines,creating an internal LAN, within your own network.

Example: Your host has the IP address of 192.168.56.1. Your virtual machine has the IPaddress of 192.168.56.101.

More closely, host:

Page 7: Network & Sharing in VirtualBox - Full Tutorial

And the guest:

This is quite similar to what VMware Server does. VMware Server has its two virtualadapters called vmnet1 and vmnet8, which are used assign NAT and host-only IPaddresses to guests. However, unlike the VirtualBox NAT adapter, VMware Server alwaysbridges the default network device on your hosts and therefore you have direct networkaccess to NAT-ed machines. You don't have this luxury on VirtualBox (yet).

But the addition of vboxnet0 in VirtualBox 3 has significantly simplified network usage inthis phenomenal product. If you wish to recall the trouble I've had to deal with in earlierrelease of VirtualBox, do take a look at my VMGL tutorial. I had to manually configureeverything. BTW, you can change the default IP address allocation, if you want.

Very importantly, please note that using the Host-only adapter does not mean your guestswill have Internet access. In fact, they won't. vboxnet0 does not have a default gateway.To make vboxnet0 also serve queries outside the local network, you will have to configureit to use another adapter for that, enable forwarding and possible reconfigure your firewallrules. At the end, you will have achieved Bridged networking, so why bother?

Host-only Adapter is useful for creating private networks, where machines need access toone another, but not necessarily outside this subnet.

Pluses: Useful for noisy software testing, penetration testing. Allows classic networksharing via IP address.

Minuses: As difficult to understand as Bridged networking for new users, no Internetaccess in the virtual machines. May introduce a security risk to other machines on theprivate network.

Page 8: Network & Sharing in VirtualBox - Full Tutorial

Internal network

Internal network is not very interesting, in my opinion. It's similar to Host-only + NAT,except the networking takes place inside the virtual network of guest machines, withoutany access for the host, plus there is no real NAT. What you get is a private LAN for yourguests only, without any access to the external world.

Sharing in VirtualBox

Now that we understand networking options, let's try some sharing. There are two waysyou can share your data in VirtualBox, either by direct network access, using IP addresses,or by using the Shared Folders feature.

Personally, I prefer the network solution, because this is how things work in the real world.You send requests to other machines via the network. If they have sharing services, likeNFS or Samba listening and if you're properly authenticated, you'll be given the list ofshares and allowed to exchange files with this server. Another way of sharing is by FTP orSSH, again, using the classic network channels.

Shared Folders is a feature where you create a folder on your host and then mount it insideyour virtual machines. It works for all network setups and uses an internal VirtualBoxsharing server to allow guest access to the shared data.

Sharing via network

Earlier, we mentioned that sharing via network is only possible for Bridged and Host-onlynetwork. Let's see two examples. The first step is to allow sharing in the guest machine.

Page 9: Network & Sharing in VirtualBox - Full Tutorial

Then, you access the virtual machine via its IP address.

On Windows:

On Windows, use Start > Run > \\XXX.XXX.XXX.XXX and replace the triplets of Xs with theactual IP of the virtual machine.

On Linux:

Type smb://XXX.XXX.XXX.XXX in the address bar of the file manager. smb:// stands forthe Samba network protocol. The triplets of Xs stand for the IP address of our guestmachine.

With Bridged networking, it looks like this:

With Host-only, it looks like this:

Page 10: Network & Sharing in VirtualBox - Full Tutorial

Ignore the title Windows shares. Samba is usually used to share with Windows hosts. NFSis more typically used for Linux machines. Samba is preferred, because it works with both.For more about Samba sharing, please take a look at this tutorial.

Shared Folders

P.S. All of the above is identical for Windows and Linux guests, by the way. To this end, Idecided to take the last set of screenshots demonstrating Shared Folders on a Windowsmachine.

Now, Shared Folders are quite simple to setup. Your first step is to configure a folder onyour host that you wish to share. For any virtual machine, open the Settings menu and goto Shared Folders.

In the right pane, you will have a list of all shared folders on the machine. You can addand remove them as you see fit. The little icons to the right are used for that purpose.

Page 11: Network & Sharing in VirtualBox - Full Tutorial

Folder Path:

This is the actual, physical path that you wish to share. On Windows, the folder path willbe something like C:\shared. On Linux, it will look something like /home/roger/shared.

Folder Name:

This is the name of the share that your guests will see. Please use names without spaces,something like Shared-folder or Banana. This name can be identical to the actual folderyou're sharing, but it does not have to be. But please note, this is not a path! It's asymbolic name for virtual machines to use, as they do not see your physical hardware.

Once you've created the path, boot you virtual machine.

On Windows:

If your virtual machine is a Windows host, you can access the network share either via thecommand line or using the Tools > Map Network Drive option in the Explorer menu.

On the command line, you need to use the net use command.

net use <drive letter> \\vboxsvr\share-name

net use is the command for mounting network drives.

<drive letter> is the drive that will be assigned the share inside your virtual machine. Itcan be any free letter, like E:, G:, X:, etc.

\\vboxsvr\share-name is the path to the share. \\vboxsvr is the VirtualBox sharing server.share-name is the actual folder name from earlier. So if you called your share Rambo, thenthe path reads \\vboxsvr\Rambo.

The command then looks like:

net use h: \\vboxsvr\Rambo

Via the Tools menu in the Explorer, it looks like this:

Page 12: Network & Sharing in VirtualBox - Full Tutorial

You can check Reconnect at logon, so you don't have to repeat this task every time youpower on the virtual machine. Once you click Finish, you will have a new drive under yourMy Computer. Opening this new drive letter will take you into the Shared folder.

On Linux:

This is done by a simple command in a terminal windows:

mount -t vboxsf share mount_point

vboxsf is the pseudo-filesystem type used to mount the Shared Folder. It's an abstracttranslation layer for the virtual sharing service used by VirtualBox.

share is the name of the folder from earlier. Remember, the name and not the path! Forexample, if our share is called Banana then share = Banana.

mount_point is any directory in your Linux tree where you wish to mount the Shared folderto. For example, /home/roger/shares-go-here.

Thus, our command looks like:

mount -t vboxsf Banana /home/roger/shares-go-here

And then, everything that is inside the shared folder on your host will be visible inside thevirtual machine by going to the above path.

To automate the task, you can add the mount option to the /etc/fstab menu. Again, formore details on how to do this, please refer to my Linux commands tutorial.

BTW, notice the help in the Settings menu, explaining how to achieve this!

And that's all.

Conclusion

Page 13: Network & Sharing in VirtualBox - Full Tutorial

Now, you know everything you need to know about VirtualBox network & sharing. Windows,Linux, bridged, host-only, NAT, sharing via network, sharing via Shared Folders, you nameit, you have it all. I hope you have enjoyed this tutorial.

Stay tuned for more good stuff.

Cheers.

Copyright @ Dedoimedo.com 2006-2013; all rights reserved

del.icio.us stumble digg reddit slashdot

Top Home Terms of use Contact me About