Pages

Sunday, June 9, 2013

virtualbox arch linux access via ssh

to access virtualbox guest via ssh from your host,

  1. on host do modprobe on following modules - vboxdrv, vboxnetadp, vboxnetflt
  2. If any of the modules not found, you should have installed linux-headers and virtualbox-host-dkms before on your host.
  3. keep your guest shutdown
  4. open virtualbox GUI
  5. go to file->preferences->network
  6. add a host-only network , this will add interface called vboxnet0 on your host.
  7. once added vboxnet0, on the same window, click edit , which will show you default ip settings (start ip, netmask, gateway etc)that you can make use of , to set ip manually/dynamically. If you plan to ssh to guest later, you probably want to disable dhcp server, as the ip keeps changing if dhcp is enabled. on the 2nd tab in the edit window, uncheck dhcp server.
  8. Now, go to individual guest settings on virtualbox gui
  9. go to network option
  10. You should already be seeing a NAT adapter being added. Add adapter2 as host-only network adapter.
  11. chose vboxnet0 as the interface.
  12. click ok and exit.
  13. start your guest.
  14. when you do ifconfig -a, you will observe that one more network interface is added to the existing list. if you did not find., perform step #1 and #2 on guest also.(reboot if necessary).
  15. you can assign a static ip like on any other linux host, for example, "ifconfig eth1 192.168.56.99 netmask 255.255.255.0 up".
  16. To make it work across reboot, you may need prepare a file called /etc/network/interfaces. google for format of the file.
  17. If you are using arch-linux, you will have to add file called /etc/systemd/system/network.service. Look for the format of this file in wiki.archlinux/networking
  18. usually the commands used are /usr/bin/ip addr .. etc. I installed net-tools and and added ifconfig command as in #15. Keep in mind that you wil lhave to provide full binary path for ifconfig.
  19. once added, you need to enable it. perform "systemctl enable network".  This will enable the service across reboot.
  20. if this fails, perform "systemctl status network.service" to check what's going wrong.

 

On a technical explanation side, virtualbox provides 3 types of networking facilities to guests.

  1. NAT(default). With this, any network packets from the guest is treated as a packet pumped from any process(virtualbox here) by host. Advantage is you don't need any tweaking to get this work, by default you will get IPs in the range 10.x.x.x... You will be able to access any network that your host is able to acess. Disadvantage is that the guest itself as a physical machine, is not accessible to external world(even to the host).
  2. host-only adapter: here, you will need to create an interface on host(vboxnet0). Need to load a driver vboxnetflt, that will acts as netowork filter to seprate out guest interface from host interface. virtualbox will internally create a router between guest and host, which makes host to see guest as a different machine all toghether(you can ssh to guest from host). advantage as well as disadvantage is that, guest will be visible only to host and other VMs but not to the external world as the IP is obtained form dhcp server of the host.
  3. bridged adapter: this will expose the guest as a remote PC to the external world also. Ip is obtained from the same dhcp server from which host is getting it.
  4. internal network: Only to connect VMs on the same host.
  5. bridged ad

No comments:

Post a Comment