Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> ซอฟต์แวร์ >> เครื่องเสมือน

เปิดใช้ File Sharing ใน VirtualBox NAT Mode เมื่อ Shared Folders ไม่พร้อมใช้งาน

มีปัญหา interesting และ convoluted: ใช้ VirtualBox virtualization tool ติดปัญหา 3D acceleration - black screen ตาม tutorial fix: ใช้ repo-provided guest additions แต่ repo set (จาก distro) ไม่เหมือน additions จาก official ISO ไม่มี shared folder driver = ไม่มี functionality นี้

ซับซ้อนกว่า: อยาก share stuff พูดใน tutorial network & sharing แต่ใช้ NAT ไม่ใช่ bridged networking guest machine ไม่ accessible จาก host โดย normal means ไม่อยากใช้ Samba ทำให้ complex มาก ลอง show วิธี transfer files host-to-guest ไม่มี shared folders ใช้ NAT ไม่ใช้ Internet ทำ local ทั้งหมด ตามมา

(ภาพประกอบ)

Problem Statement

เห็น issue: ต้อง make machine more visible โดย bridge network adapter ซึ่งอาจไม่ใช่สิ่งที่ต้องการ โดยเฉพาะถ้า 'noisy' VM ต้อง setup file sharing servers งานมากกว่า trivial อีกทาง: ใช้ VirtualBox ISO disable 3D acceleration จน black screen หาย แล้วใช้ shared folders feature

เรื่อง repo packages: มี mostly stuff - graphics acceleration, mouse integration, screen resizing, clipboard sharing แต่ไม่มี folders พยายาม mount shared folder manual:

mount -t vboxsf  
mount: unknown filesystem type 'vboxsf'

Solution: Port Forwarding

VirtualBox ให้ advanced network rules สำหรับ NAT-ed machines ไม่ต่างจาก router translate local IPs ไป public-facing และกลับกัน VirtualBox = router here เห็นกับ Docker: map host ports ไป container ports เข้าถึง local system แต่จริงๆ เชื่อม container/VM

Select VM > Settings Under Networking NAT type expand Advanced section bottom Click Port Forwarding จะได้ table ใส่รายละเอียด: Host IP - IP ของ interface ที่จะใช้ (อาจหลายอัน easiest: localhost 127.0.0.1 เพราะทำงานได้แม้ interfaces อื่น down หรือ no outside connectivity) Host Port - 'virtual' address ที่จะ connect เช่น SSH map port 2222 เป็น Host Port connect ที่ port นี้ = connect Guest IP at Guest Port ใน table

(ภาพประกอบ port forwarding settings)

เชื่อมต่อด้วย SSH (Connect with SSH)

มี connection จริง SSH for Linux! เพราะปัญหาใน Linux Windows ไม่มี black screen 3D acceleration + guest additions ISO fine Ergo Linux

เชื่อม host-to-guest SSH (port 2222) ขั้นแรก: ติดตั้งและรัน openssh-server ใน guest OS ตรวจสอบ guest ไม่ใช้ firewall block incoming connections ทดสอบ:

ssh -p 2222 roger@127.0.0.1
The authenticity of host '[127.0.0.1]:2222 ([127.0.0.1]:2222)' can't be established...
Are you sure you want to continue connecting (yes/no)?

(ภาพประกอบ SSH connection)

แค่ test connectivity ต้องการ SCP copy files host-to-guest ต้อง specify custom port SSH ใช้ lowercase -p ส่วน SCP ใช้ uppercase -P สำหรับ port numbers:

scp -P 2222 "file" roger@127.0.0.1:/home/roger/"location"/
"file"                                          100% 8244KB 135.0MB/s  00:00

(ภาพประกอบ SCP transfer)

สรุป (Conclusion)

ชอบ exercises แบบนี้ innovative และ fun เหมือน KVM & bridged network trick 看起來อาจต้อง bridged networking setup Samba/NFS หรือ email files tedious แทน work around ด้วย port-forwarding และ SSH ทั้งคู่ simple, non-intrusive, easy setup/disable

วันนี้เรียนรู้เยอะ: missing features repo guest additions, advanced networking rules port forwarding, SSH/SCP subtle differences port numbers, อื่นๆ จบแล้ว จดจำ: มี neat way แก้ปัญหาเสมอ ถ้ามีความอดทนและเป็นระบบ Take care.

Cheers.