Putty fails to connect to second VirtualBox VM on Windows 10 Host

puttyvirtualbox

I'm running VirtualBox on Windows 10. I have been using PuTTY to connect to my Ubuntu 16.04 VM for some time now. I've finally decided that I want to use Ubuntu 18.xx. So I spun up a new VM and configured it just like my 16.04 VM.

I've added an SSH key and done the whole import -> puttygen -> ppk thing.

I've done that several times over the last 6 months. And I've failed to connect to the second VM every time.

I notice that both VMs have the same IP address behind the NAT, they're both 10.0.2.15. I get that from ifconfig. Is that significant or irrelevant?

I've tried adding a port-forward rule, a bridged-adaptor and a million other things that just didn't work.

Question

What kind of setup do I need to be able to SSH in to both running VMs?

What is my problem?

  • Am I overlooking an obvious connection string?
  • Am I being oblivious to some basic networking principles?
  • Am I not allowed to do this?

Desired behavior

I would like to

  1. Run two VMs at the same time.
  2. Run two instances or PuTTY on my host.
    • One PuTTY will ssh into machine A
    • One PuTTY will ssh into machine B
  3. Run PuTTY on my laptop (same office network as desktop)
    • Point this at either VM.

I swear I am not lazy. I've spent countless hours over the last few months trying to get this to work. It's one of those projects that's a nice to have that I keep coming back to every other month as time permits.

Current behavior

I can use PuTTY from my host machine to ssh into my 16.04 VM. I can use PuTTY from my laptop to ssh into my 16.04 VM.

I cannot ssh into the 18.10 VM from the host machine or from the laptop.

Best Answer

To connect VMs from host, VMs need a Host-Only network interface. The main goal here is to create two network interface in VM. First network adapter will have NAT network (DHCP enabled by default). This connects VM with outer Internet. Second adapter will be attached to Host-Only interface. This connects VM with host OS for SSH, RDP, Docker or other connections.

Here are the configurations for my setup. These may vary in your system. Change these IPv4 IP addresses as wish but be careful about that the IPs should not conflict with other private networks. The Host-Only network should be in same subnet both in host and guest OS.

  • Host OS: Windows 10

    • Host-Only adapter name: VirtualBox Host-Only Ethernet Adapter
    • Host-Only adapter IP address: 192.168.99.1/24 gateway -- optional
  • Guest OS: Ubuntu 18.10

    • VM name: Ubuntu
    • NAT adapter (eth0): IPv4 -- 10.0.2.15/24 (DHCP) gateway -- 10.0.2.2
    • Host-Only adapter (eth1): 192.168.99.100 (static) gateway -- optional

Let assume Ubuntu VM was installed in VirtualBox. Now follow these commands to configure network in host side. Same steps can be done in VirtualBox Manager Window.

  • Create Host-Only Interface (optional, pre-installed): VBoxManage hostonlyif create

  • Add static IPv4 address (or use ncpa.cpl): VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter" --ip 192.168.99.1 --netmask 255.255.255.0

  • Attach Adapter 1 to NAT: VBoxManage modifyvm Ubuntu --nic1 nat

  • Attach Adapter 2 to Host-Only interface: VBoxManage modifyvm Ubuntu --nic2 hostonly

Start the VM. Open terminal, disable interfaces with sudo ifdown -a command. Add static IPv4 IP address in Host-Only network interface (eth1) by adding these lines in /etc/network/interfaces file:

auto eth1
iface eth1 inet static
address 192.168.99.100
netmask 255.255.255.0

Save that file. Enable all interfaces with sudo ifup -a command. Check if both network interfaces are working with ping 10.0.2.2 and ping 192.168.99.1 commands. If both works then:

  • Install SSH: sudo apt-get install ssh
  • Create ssh key pairs: sudo ssh-keygen -A
  • Start SSH service: sudo service ssh restart

Start putty or any ssh client with user@192.168.99.100 from host side. If Windows firewall will block connections allow 192.168.99.0/24 network in outbound/inbound rules.

Further Readings: