仮想マシン
 Computer >> コンピューター >  >> ソフトウェア >> 仮想マシン

VirtualBox でのネットワークと共有 - 完全なチュートリアル

これは、VirtualBox の管理に関する 4 回目の記事です。今日は、VirtualBox のネットワークと共有について知っておくべきことをすべてお教えします。

仮想マシンを構成する 3 つの異なる方法と、ホストマシンと仮想マシン間でデータを共有する 3 つの異なる方法を紹介します。このチュートリアルを習得すれば、VirtualBox を楽しく自信を持って使用するために知っておくべきことがすべてわかります。フォローしてください。

はじめに

詳細については、次の記事を参照してください。それらは、今日の資料を簡単かつ楽しくフォローするために必要な背景を提供します:

VirtualBox Guest Additions のインストール方法 - チュートリアル

VirtualBox 3はすごい!

VirtualBox 3 Compiz スライドショー

VirtualBox 3 の DirectX - 純粋な喜びがここにあります

同様に、このシリーズの最初の 3 回の記事を読む必要があります:

VirtualBox でディスクのクローンを作成する方法 - チュートリアル

VirtualBox にハードディスクを追加する方法 - チュートリアル

VirtualBox でディスクを拡張/縮小する方法 - チュートリアル

では、始めましょう。

VirtualBox ネットワーク オプション

インストール済みの仮想マシンのいずれかについて、[設定]> [ネットワーク] をクリックします。ここから楽しみが始まります。これがデフォルトのビューです。仮想マシンは、最大 4 つのネットワーク アダプタを持つことができます。必要に応じて選択的に有効にすることができます。ほとんどの人は 1 つだけを必要とします。

アダプタ タイプは、VirtualBox が仮想マシンに公開する仮想化されたハードウェアを定義します。アダプタ タイプの 1 つに問題がある場合は、別のタイプを試すことができます。 PCnet-FAST III がデフォルトで選択されています。

古いマシン用の PCnet-FAST II と、2 つのサーバー バージョンを含む 3 種類の Intel PRO/1000 カードもあります。これは、実稼働環境で VirtualBox を実行しているユーザーに役立つはずです。ホームユーザーにとって、選択はかなり透過的です。

最も興味深い部分は Attached to:セクションです。このカテゴリは、ネットワーク アダプターが既存の物理ハードウェアとどのようにインターフェイスするかを定義します。設定が異なると、結果が著しく異なります。

ネットワークの種類

ここには、NAT (デフォルト)、ブリッジ、内部ネットワーク、およびホストのみの 4 つのオプションがあります。もちろん、付属しないもタイプですが、それ自体は実際に使用できるタイプではありません。

ネットワーク アドレス変換 (NAT)

NAT は、仮想マシンが外部からルーティングできないプライベート IP アドレスを持つことを意味します。

例:ホストは 192.168.1.1 です。 VirtualBox NAT デバイスは 10.0.2.1 としてマークされます。したがって、仮想マシンには 10.0.2.x の範囲内の任意のアドレスが割り当てられます。 10.0.2.x/24 サブネット内のマシンへのアクセスをルーティングするものがないため、ホストからアクセスできなくなります。

このセットアップは、ゲストが持つ IP アドレスをあまり気にしない場合に便利です。ただし、転送が必要な場合や、サービスを外の世界に公開する必要がある場合は良くありません。同様に、この設定はネットワーク アクセスを介した共有には適していません。

プラス:シンプル&隔離。

マイナス:仮想マシンへのルートがない、ネットワーク共有がない。

ブリッジアダプタ

ブリッジ アダプタとは、実行中のすべての仮想マシンが、現在アクティブなデフォルト ネットワーク アドレスがその IP アドレスを取得したのと同じソースから IP アドレスを取得しようとすることを意味します。したがって、2 つが接続されているため、ブリッジという用語が使用されます。

アクティブなネットワーク デバイスが複数ある場合は、VirtualBox とブリッジするデバイスを選択できます。この場合、ワイヤレス アダプタ wlan0 を使用します。

例:ホストがルーターから 192.168.1.100 のアドレスをリースしました。仮想マシンは、ルーターから 192.168.1.103 のアドレスをリースします。 2 台のマシンが同じネットワークを共有するようになり、すべての標準ルールが適用されます。実際には、仮想マシンは LAN 上の別の IP アドレスです。

より厳密には、ホスト:

そしてゲスト:

デバイス (スイッチ、ルーター、ISP など) で複数の IP アドレスのリースが許可されていない場合、このセットアップは機能しません。したがって、インターネットに直接アクセスできるコンピュータでは、ブリッジ ネットワークを使用できない場合があります。

プラス:ポート フォワーディングとサービスを有効にして、ネットワークを柔軟に管理できます。従来の方法でネットワーク共有を許可します。

短所:直接のインターネット アクセスでは機能しない可能性があり (ルーターが必要)、新しいユーザーには理解が難しく、マシンがネットワークに公開され、セキュリティに影響する可能性があります。

ホストオンリー アダプター

Host-only Adapter は非常に興味深いものです。 IP アドレスをリースするために vboxnet0 と呼ばれる専用のネットワーク デバイスを使用する点を除いて、ブリッジ アダプターと非常に似ています。

ホスト マシンは事実上の VirtualBox ルーターであり、IP アドレスは 192.168.56.1 です。ホストのみのセットアップで実行されている仮想マシンがない場合、アダプタは使用されていません。ただし、仮想マシンが起動すると、このアダプタは仮想マシンに IP アドレスを提供し、独自のネットワーク内に内部 LAN を作成します。

例:ホストの IP アドレスは 192.168.56.1 です。仮想マシンの IP アドレスは 192.168.56.101 です。

もっと詳しく、ホスト:

そしてゲスト:

これは、VMware Server が行うことと非常によく似ています。 VMware Server には vmnet1 および vmnet8 と呼ばれる 2 つの仮想アダプタがあり、これらはゲストに NAT およびホストオンリー IP アドレスを割り当てるために使用されます。 However, unlike the VirtualBox NAT adapter, VMware Server always bridges the default network device on your hosts and therefore you have direct network access 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 in this phenomenal product. If you wish to recall the trouble I've had to deal with in earlier release of VirtualBox, do take a look at my VMGL tutorial. I had to manually configure everything. 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 guests will 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 configure it to use another adapter for that, enable forwarding and possible reconfigure your firewall rules. 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 to one another, but not necessarily outside this subnet.

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

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

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, without any access for the host, plus there is no real NAT. What you get is a private LAN for your guests 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 ways you 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, like NFS or Samba listening and if you're properly authenticated, you'll be given the list of shares and allowed to exchange files with this server. Another way of sharing is by FTP or SSH, again, using the classic network channels.

Shared Folders is a feature where you create a folder on your host and then mount it inside your virtual machines. It works for all network setups and uses an internal VirtualBox sharing 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-only network. Let's see two examples. The first step is to allow sharing in the guest machine.

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 the actual IP of the virtual machine.

On Linux:

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

With Bridged networking, it looks like this:

With Host-only, it looks like this:

Ignore the title Windows shares. Samba is usually used to share with Windows hosts. NFS is 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

追記All of the above is identical for Windows and Linux guests, by the way. To this end, I decided to take the last set of screenshots demonstrating Shared Folders on a Windows machine.

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

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

Folder Path:

This is the actual, physical path that you wish to share. On Windows, the folder path will be 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 folder you're sharing, but it does not have to be. But please note, this is not a path! It's a symbolic 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 the command 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 \\vboxsvr\share-name

net use is the command for mounting network drives.

is the drive that will be assigned the share inside your virtual machine. It can 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, then the 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:

You can check Reconnect at logon, so you don't have to repeat this task every time you power on the virtual machine. Once you click Finish, you will have a new drive under your My 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 abstract translation 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! For example, 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 folder to. 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 the virtual machine by going to the above path.

To automate the task, you can add the mount option to the /etc/fstab menu. Again, for more 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!

それだけです。

結論

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 name it, you have it all. I hope you have enjoyed this tutorial.

Stay tuned for more good stuff.

乾杯。


  1. VirtualBox 3.0.0 はすごい!

    私のお気に入りのデスクトップ仮想化ソフトウェアには、VirtualBox と VMware Server があります。どちらも気に入って使っています。それらは全体的に非常に似ていますが、他の製品にはない独自の機能のサブセットをユーザーに提供し、互いにうまく補完しています. ほんの数日前、興奮の渦中に VirtualBox 3.0.0 がリリースされました。これは、前任者と VMware Server の両方に対して、どれだけうまく機能するかを確認する絶好の機会でした。深呼吸して、私についてきてください。長い紹介であなたを苦しめますが、それだけの価値があるはずです。 比較 ...

  2. 仮想マシンでの 3D アクセラレーション - パート 2:VirtualBox &OpenGL - チュートリアル

    これは、仮想マシンでの 3D 仮想化の構成と使用に特化した 3 つの記事の 2 番目です。今日は、Windows または Linux ホストにインストールされた VirtualBox で実行されている Windows 仮想マシンの OpenGL アプリケーション (およびゲーム) の 3D アクセラレーションを有効にする方法を学習します。 最初の記事では、VMware 製品を使用して、Windows で DirectX プログラムの 3D アクセラレーションを有効にする方法について説明しました。ホスト プラットフォームの選択は問題ではありませんでした。 Windows ホストと Linux