Computer >> Hướng Dẫn Máy Tính >  >> Phần Mềm >> Máy Ảo

Thành Thạo Networking & Sharing VirtualBox: Hướng Dẫn Bước Đi Bước Hoàn Chỉnh

Bài 4 series quản trị VirtualBox. Hôm nay dạy tất cả về networking và sharing VirtualBox.

Sẽ show 3 phương pháp cấu hình network VM và 3 cách share data giữa host và guest. Sau khi master, bạn sẽ biết tất cả dùng VirtualBox confidently. Follow me.

Giới Thiệu

Chi tiết hơn, đọc các bài sau cho background cần thiết:

  • How to install VirtualBox Guest Additions - Tutorial
  • VirtualBox 3 is amazing!
  • VirtualBox 3 Compiz slideshow
  • DirectX in VirtualBox 3 - Pure joy is here

Cũng đọc 3 phần đầu series:

  • How to clone disks in VirtualBox - Tutorial
  • How to add hard disks in VirtualBox - Tutorial
  • How to expand/shrink disks in VirtualBox - Tutorial

Bắt đầu.

Tùy Chọn Mạng VirtualBox

VM cài đặt -> Settings > Network. Fun begins. Default view. Mỗi VM tối đa 4 network adapters. Enable selective. Hầu hết chỉ cần 1.

Adapter Type: hardware ảo VirtualBox expose cho VM. Vấn đề adapter type -> thử type khác. PCnet-FAST III default.

Còn PCnet-FAST II cho máy cũ, 3 loại Intel PRO/1000 (kể 2 Server version, useful production). Home user: transparent choice.

Phần thú vị: Attached to. Category này define adapter interface với physical hardware. Setup khác -> kết quả khác biệt.

Loại Mạng

4 options: NAT (default), Bridged, Internal network, Host Only. Not attached cũng là type nhưng không dùng được.

Network Address Translation (NAT)

NAT: VM có private IP không routable từ ngoài.

VD: Host 192.168.1.1. VirtualBox NAT device 10.0.2.1. VMได้ IP range 10.0.2.x. Không route access 10.0.2.x/24 -> inaccessible từ host.

Setup hữu ích khi không care IP guest, each to its own. Không tốt nếu cần forwarding hoặc expose services ra ngoài. Cũng không tốt network sharing.

Pluses: simplicity & seclusion. Minuses: no route to VM, no network sharing.

Bridged Adapter

Bridged Adapter: VM thử lease IP từ cùng nguồn active network device của host. Hence "bridged".

Nếu >1 active network device, chọn bridge với cái nào. Case này: Wireless adapter wlan0.

VD: Host lease 192.168.1.100 từ router. VM lease 192.168.1.103 từ router. 2 máy share same network, standard rules apply. VM = IP khác trên LAN.

Setup không work nếu device (switch, router, ISP) không cho lease >1 IP. Computer direct Internet access có thể không dùng Bridged.

Pluses: flexible management port forwarding/services. Classic network sharing. Minuses: có thể không work direct Internet (cần router), khó hiểu new user, expose machines network security implications.

Host-only Adapter

Host-only Adapter: similar Bridged nhưng dùng dedicated network device vboxnet0 lease IP.

Host = de-facto VirtualBox router, IP 192.168.56.1. Adapter không dùng nếu không VM chạy Host-only. Khi VM lên, adapter serve IP cho VM, tạo internal LAN trong network của bạn.

VD: Host 192.168.56.1, VM 192.168.56.101.

Giống VMware Server: vmnet1, vmnet8 assign NAT/host-only IP cho guest. Khác VirtualBox NAT adapter, VMware luôn bridge default network device host -> direct network access NAT-ed machines. VirtualBox chưa có luxury này (yet).

Nhưng vboxnet0 trong VirtualBox 3 đơn giản hóa network usage. Nhớ trouble earlier release, xem VMGL tutorial. Phải config thủ công. Có thể đổi default IP allocation.

Quan trọng: Host-only adapter KHÔNG có nghĩa VM có Internet access. Thực tế KHÔNG. vboxnet0 không default gateway. Muốn vboxnet0 serve outside queries -> config dùng adapter khác, enable forwarding, reconfigure firewall. Cuối cùng đạt Bridged networking -> why bother?

Host-only useful tạo private network, machines cần access nhau, không cần outside subnet.

Pluses: noisy software testing, penetration testing. Classic network sharing via IP. Minuses: khó hiểu như Bridged cho new user, no Internet trong VM. Có thể introduce security risk private network.

Internal network

Internal network: not interesting. Giống Host-only + NAT nhưng networking bên trong virtual network guest, không access host, không real NAT. Private LAN cho guest only, không external access.

Sharing trong VirtualBox

Hiểu network options, thử sharing. 2 cách share data: direct network access (IP) hoặc Shared Folders feature.

Cá nhân thích network solution: real world works như vậy. Gửi request qua network. Nếu sharing services (NFS/Samba) listening + authenticated -> list shares, exchange files. FTP/SSH cũng dùng network channels.

Shared Folders: tạo folder trên host, mount vào VM. Work mọi network setup, dùng internal VirtualBox sharing server cho guest access shared data.

Sharing qua Network

Trước: sharing qua network chỉ Bridged và Host-only. 2 ví dụ. Bước 1: cho phép sharing trong guest.

Truy cập VM qua IP.

Trên Windows:

Start > Run > \\XXX.XXX.XXX.XXX (thay IP VM).

Trên Linux:

smb://XXX.XXX.XXX.XXX trong address bar file manager. smb:// = Samba protocol. XXX = IP guest.

Bridged networking trông như:

Host-only trông như:

Ignore title "Windows shares". Samba dùng share với Windows host. NFS typical Linux-Linux. Samba preferred vì work both. Xem Samba sharing tutorial.

Shared Folders

P.S. Tất cả identical Windows/Linux guest. Screenshots demo Shared Folders trên Windows.

Shared Folders setup đơn giản. Bước 1: config folder host muốn share. VM Settings > Shared Folders.

Right pane: list shared folders. Add/remove icons bên phải.

Folder Path:

Physical path thực tế share. Windows: C:\shared. Linux: /home/roger/shared.

Folder Name:

Tên share guest thấy. Dùng tên không space: Shared-folder, Banana. Có thể trùng folder thực tế nhưng không bắt buộc. Lưu ý: KHÔNG phải path! Tên symbolic cho VM dùng, vì VM không thấy physical hardware.

Tạo xong path, boot VM.

Trên Windows:

VM Windows: access network share qua command line hoặc Tools > Map Network Drive trong Explorer.

Command line: net use command.

net use \\vboxsvr\share-name

net use: mount network drives. : drive assign share trong VM (E:, G:, X:...). \\vboxsvr\share-name: path share. \\vboxsvr = VirtualBox sharing server. share-name = Folder Name trước. VD share Rambo -> \\vboxsvr\Rambo.

Command: net use h: \\vboxsvr\Rambo

Tools menu Explorer:

Check Reconnect at logon -> không lặp lại mỗi lần power on VM. Click Finish -> new drive My Computer. Mở drive letter -> vào Shared folder.

Trên Linux:

Terminal command đơn giản:

mount -t vboxsf share mount_point

vboxsf: pseudo-filesystem type mount Shared Folder. Abstract translation layer virtual sharing service VirtualBox.

share: tên folder trước. NHỚ: tên, KHÔNG phải path! VD share Banana -> share = Banana.

mount_point: directory bất kỳ Linux tree mount Shared folder. VD /home/roger/shares-go-here.

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

Sau đó, mọi thứ trong shared folder host visible trong VM tại path trên.

Automate: add mount option vào /etc/fstab. Chi tiết Linux commands tutorial.

BTW, notice help Settings menu explain cách làm!

Xong.

Kết Luận

Bây giờ bạn biết tất cả VirtualBox network & sharing. Windows, Linux, bridged, host-only, NAT, sharing via network, Shared Folders. Hy vọng enjoy tutorial.

Stay tuned more good stuff.

Cheers.