Posted by : at

Category : engineering

Ever wanted to connect to a VirtualBox VM via SSH, SCP or others and found out you couldn’t? This is because, by default you don’t have access to the ports of your VM. Today I’ll show you how you can enable port forwarding so you can easily connect to all your VMs.

Software used:

##

1. Find your guest VMs IP

Fire up your virtual machine, login and find you ipaddress. In most Linux distributions you can do this by using the command 

ifconfig

or 

ip a

. Note down this ip, we will use it in the next step.

##

2. Enable portforwarding

In VirtualBox, select your VM and click Settings. Go to Network -> Adapter 1 -> under Advanced -> Port Forwarding. Click the add button, and a new rule will appear. Edit its IP to be 127.0.1.1 (a loopback address you can easily remember), for the host port use 22 (SSH, I’ll add a list of commonly used ports at the bottom of this article), and for the guest port 22. For the guest ip use the one you got above.

##

3. Connect with PuTTY to the VM

Open up PuTTY and connect to 127.0.1.1:22. Login and voila, you should now be connected to the VM. You can use this procedure for any other port.

 

##

Appendix – list of common ports

  • 21 – FTP (File Transfer Protocol, used to copy files between remote computers)
  • 22 – SSH, SCP (Secure Shell, open a terminal on the remote computer; Secure Copy, secure file transfer)
  • 80 – HTTP (HyperTextTransferProtocol, used by most sites today)
  • 443 – HTTPS (HTTP over TLS/SSL, used to securely transfer data between a site and a client)
  • 3306 – MySQL (MySQL database port)