September 14, 2020

198 words 1 min read

HowTo - SSH with Virtual Box

HowTo - SSH with Virtual Box

Want to connect to Virtual Box VM with NAT network adapter via SSH, but don’t want to reconfigure network? There is a simple solution.

By default Virtual Box VMs use NAT as for network adapter. In this configuration VM can connect to host network, but host network can’t connect to VM. Which obviously makes connection to guest SSH server impossible.

How to fix it? There is a simple way - your can forward guest SSH port to host port and connect to it. Just follow the steps below:

Step 1: Open Network configuration of VM

Go to VM settings > Network > Advanced

Virtual Box port forwarding

Select your NAT network adapter and click ‘Port Forwarding’

Step 2: Configure port forwarding

Add new port forwarding rule with the following parameters:

  • Name - Name for your rule
  • Protocol - TCP
  • Host IP - 127.0.0.1 or other loopback address
  • Host Port - Port to be used on host
  • Guest IP - NAT IP of your VM
  • Guest Port - Port used by SSH server on your VM

Virtual Box port forwarding

Step 3: Connect to the guest VM

Now you can connect to your VM from host:

ssh 127.0.0.1 -p 2222

Image credits: