Virtualbox connect from host to guest via ssh and enable internet on guest

  1. Open Oracle VM Virtualbox Manager

    virtualbox_manager

  2. Place the cursor on the machine that you want to configure and press the button Settings.
    -> Network -> Adapter 1-> check Enable Network Adapter -> in Attached to choose NAT.
    -> in Advanced section -> press Port Forwarding  -> in Port Forwarding Rules, press addition button ->
    Fill the rule , by the following way:
    Host IP: (leave blank)
    Host Port: 22   (or any port that your host has free)
    Guest IP: (leave blank)
    Guest Port: 22

    vm_settings
    rules

  3. Start up the VM and connect to the guest using ssh.
    Hostname: localhost (or your machine name)
    Port: 22 (it is the same that we have indicated during rule configuration field Host Port)

    putty

  4. If you are not using proxy, than you can think that the post finished for you. You can connect to the guest from os and also you have an internet on your guest.

    But if proxy is used then you should configure parameter http_proxy.
    You can enter this variable information in every user’s  ~/.bash_profile or you can do it globally in /etc/profile file.

    #add the following entry in profile file

    [root@oracle01 ~]# vi /etc/profile
    export http_proxy=http://proxyservername.domain.ge:8080

    Logout and login for changes to take effect.

Configuring SSH access for VirtualBox Host to Guest

I have installed VirtualBox with CentOS. I’ve decided that it would be easier to connect VBox from Host terminal via SSH then using Vbox GUI environment. I’ve found this process a little bit difficult and fortunately have solved it.

Now, I want to share my knowledge with you:

Note: <VBoxName> will be the name of the Virtual Box Machine. To find it type command “hostname” on guest machine.

1. Open up the terminal window on Host machine, and run the following:

$ VBoxManage setextradata <VBoxName> “VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort” 2222


1. 1 If you encounter the following error(if not ignore this section),

VBoxManage: error: Could not find a registered machine named “VBoxName”...
do the following:
$ VBoxManage createvm –name <VBoxName> –register

 

2.

$ VBoxManage setextradata <VMname> “VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort” 2222

3.

$ VBoxManage setextradata <VMname> “VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort” 22

4.

$ VBoxManage setextradata <VMname> “VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol” TCP

5.  Close the guest Machine Window (reboot is not enough)


6.
Open up the terminal window on Host machine and run:

$ ssh -l username -p 2222 <localhost>

Where <localhost> is the name of the Host machine.

6.1  If you get the following error(if not ignore this section):

ssh-exchange-identification connection closed by remote host

One of the solution is to start ssh on both HOTS/GUEST machines:

$ /etc/init.d/sshd start

7. That is all, and one more hint: username by which you want to connect to the Guest machine must have password.