如何透過 NAT 連線到 guest OS

   如何使用分享資料夾



      Ying-Shiuan Pan



                        Ying­Shiuan Pan
如何透過 NAT 連線到 guest OS
   Where is the VM profile?
   open­ssh server
   What is NAT?
   Add port forwarding rule
   Try to connect to guest Os

    疑難排解
   Reference


                                 Ying­Shiuan Pan
Where is the VM profile?
   Windows XP
          C:Documents and
            Settings???.VirtualBox
   Linux
          /home/???/.VirtualBox


   each VM's profile in 
          .VirtualBox/Machines/VM_name
                 VM_name.xml

                                       Ying­Shiuan Pan
ssh server

    安裝
         $ sudo apt-get install openssh-
           server

   啟動 ssh server ( 也許需要 )
         $ sudo /etc/init.d/ssh restart


    測試
         $ ssh localhost


                                     Ying­Shiuan Pan
What is NAT?




鳥哥
http://linux.vbird.org/linux_server/0250simple_firewall.php


                                                              Ying­Shiuan Pan
Check your NIC type




                      Ying­Shiuan Pan
Plan your port forwarding rule
   What is the name of your guest OS?
          eg. Ubuntu 904
   Which port in host OS?
          eg. 32790
   Which port in guest OS?
          eg. 22




                                         Ying­Shiuan Pan
add port forwarding rule
   Windows:
          開始 → 執行 → cmd
          cd "Program FilessunVirtualBox"
   Linux
          應用程式 → 附屬應用程式 → 終端機 (cht)
          Applications → Accessories → Terminal (eng)
       




                                                Ying­Shiuan Pan
add port forwarding rule
   $ VBoxManage setextradata "VM_name"
      "VBoxInternal/Devices/pcnet/0/LUN#0/Config/
      guestssh/Protocol" TCP


   $ VBoxManage setextradata "VM_name"
      "VBoxInternal/Devices/pcnet/0/LUN#0/Config/
      guestssh/GuestPort" 22


   $ VBoxManage setextradata "VM_name"
      "VBoxInternal/Devices/pcnet/0/LUN#0/Config/
      guestssh/HostPort" 32790


                                      Ying­Shiuan Pan
add port forwarding rule
   "VM_name"
         the name of the virtual machine
   pcnet
         the NIC type
                  Intel PRO... (82540em)    →    e1000
                  PCnet­FAST (Am79c973)     →    pcnet
   guestssh
         the name of the rule
   TCP, 22, 32790
         protocol, guest OS port, host OS port
                                                   Ying­Shiuan Pan
add port forwarding rule




                      Ying­Shiuan Pan
Try to connect to guest OS (1)




                          Ying­Shiuan Pan
Try to connect to guest OS (2)




                          Ying­Shiuan Pan
    Ying­Shiuan Pan
疑難排解
   從 guest OS 無法連到自己的 ssh
         確認 guest OS 的 ssh 是否打開
                從 guest OS 連線到自己試試看
   從 host 無法連線到 guest
         確認 port forwarding rule 是否正確
                查看該 VM 的 profile (.xml)
         檢查 guest OS 的防火牆是否被打開了
             
                 關掉他



                                           Ying­Shiuan Pan
疑難排解
   從其他電腦無法連線到 guest OS
         是否使用 IP 分享器
               外界電腦連入需要作 IP 分享器的 port forwarding
                 設定
         是否 host OS 的防火牆擋住了外面連線
            
                視不同的防火牆作設定




                                         Ying­Shiuan Pan
Reference
   http://log­keep.blogspot.com/2007/09/virtualbox­
      nat­port­forwarding.html
   http://blog.yam.com/flyzc/article/15137400
   http://koukaipan.pixnet.net/blog/post/23993776




                                           Ying­Shiuan Pan
如何使用分享資料夾
   Install VirtualBox Guest Addiction first
   Plan your shared folder
   Add your shared folder
   Mount your shared folder




                                               Ying­Shiuan Pan
Plan your shared folder
   Directory in host OS
          /data/vbox_shared          (a)


   Directory in guest OS
          /mnt/vbox_shared           (b)


   The name of the shred directory
          vbox_shared                (c)

                                       Ying­Shiuan Pan
Add your shared folder




               (a)
               (c)



                     Ying­Shiuan Pan
Mount the shared folder
   Create mount point
                                           (b)
              $ sudo mkdir /mnt/vbox_shared
   Do mount
              $ sudo mount -t vboxsf (c)
                vbox_shared /mnt/vbox_shared (b)
   test
              $ cd /mnt/vbox_shared (b)
              $ ls


                                                 Ying­Shiuan Pan
screenshot




             Ying­Shiuan Pan

using Virtualbox NAT and shared folder

  • 1.
    如何透過 NAT 連線到guest OS 如何使用分享資料夾 Ying-Shiuan Pan   Ying­Shiuan Pan
  • 2.
    如何透過 NAT 連線到guest OS  Where is the VM profile?  open­ssh server  What is NAT?  Add port forwarding rule  Try to connect to guest Os  疑難排解  Reference   Ying­Shiuan Pan
  • 3.
    Where is the VM profile?  Windows XP  C:Documents and Settings???.VirtualBox  Linux  /home/???/.VirtualBox  each VM's profile in   .VirtualBox/Machines/VM_name  VM_name.xml   Ying­Shiuan Pan
  • 4.
    ssh server  安裝  $ sudo apt-get install openssh- server  啟動 ssh server ( 也許需要 )  $ sudo /etc/init.d/ssh restart  測試  $ ssh localhost   Ying­Shiuan Pan
  • 5.
  • 6.
    Check your NIC type   Ying­Shiuan Pan
  • 7.
    Plan your port forwarding rule  What is the name of your guest OS?  eg. Ubuntu 904  Which port in host OS?  eg. 32790  Which port in guest OS?  eg. 22   Ying­Shiuan Pan
  • 8.
    add port forwarding rule  Windows:  開始 → 執行 → cmd  cd "Program FilessunVirtualBox"  Linux  應用程式 → 附屬應用程式 → 終端機 (cht)  Applications → Accessories → Terminal (eng)    Ying­Shiuan Pan
  • 9.
    add port forwarding rule  $ VBoxManage setextradata "VM_name" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ guestssh/Protocol" TCP  $ VBoxManage setextradata "VM_name" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ guestssh/GuestPort" 22  $ VBoxManage setextradata "VM_name" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ guestssh/HostPort" 32790   Ying­Shiuan Pan
  • 10.
    add port forwarding rule  "VM_name"  the name of the virtual machine  pcnet  the NIC type  Intel PRO... (82540em)  → e1000  PCnet­FAST (Am79c973)  → pcnet  guestssh  the name of the rule  TCP, 22, 32790  protocol, guest OS port, host OS port   Ying­Shiuan Pan
  • 11.
    add port forwarding rule   Ying­Shiuan Pan
  • 12.
  • 13.
  • 14.
      Ying­Shiuan Pan
  • 15.
    疑難排解  從 guest OS 無法連到自己的 ssh  確認 guest OS 的 ssh 是否打開  從 guest OS 連線到自己試試看  從 host 無法連線到 guest  確認 port forwarding rule 是否正確  查看該 VM 的 profile (.xml)  檢查 guest OS 的防火牆是否被打開了  關掉他   Ying­Shiuan Pan
  • 16.
    疑難排解  從其他電腦無法連線到 guest OS  是否使用 IP 分享器  外界電腦連入需要作 IP 分享器的 port forwarding 設定  是否 host OS 的防火牆擋住了外面連線  視不同的防火牆作設定   Ying­Shiuan Pan
  • 17.
    Reference  http://log­keep.blogspot.com/2007/09/virtualbox­ nat­port­forwarding.html  http://blog.yam.com/flyzc/article/15137400  http://koukaipan.pixnet.net/blog/post/23993776   Ying­Shiuan Pan
  • 18.
    如何使用分享資料夾  Install VirtualBox Guest Addiction first  Plan your shared folder  Add your shared folder  Mount your shared folder   Ying­Shiuan Pan
  • 19.
    Plan your shared folder  Directory in host OS  /data/vbox_shared (a)  Directory in guest OS  /mnt/vbox_shared (b)  The name of the shred directory  vbox_shared (c)   Ying­Shiuan Pan
  • 20.
    Add your shared folder (a) (c)   Ying­Shiuan Pan
  • 21.
    Mount the shared folder  Create mount point (b)  $ sudo mkdir /mnt/vbox_shared  Do mount  $ sudo mount -t vboxsf (c) vbox_shared /mnt/vbox_shared (b)  test  $ cd /mnt/vbox_shared (b)  $ ls   Ying­Shiuan Pan
  • 22.
    screenshot   Ying­Shiuan Pan