Virtualbox, ssh from Ubuntu host to Ubuntu guest: connection refused

Peregring-lk

I'm trying to connect to my virtual machine and I'm continously getting the following error:

ssh: connect to host 192.168.56.101 port 22: Connection refused

My host OS is a fresh installed Ubuntu 18.04 and the virtual machine is an old Ubuntu 14.04 (the virtual machine isn't a fresh install; rather, I've created a new virtual machine and then import the virtual hard disk file .dvi from my old laptop where sshing worked without issues).

I can ping to the machine without package loss, and I think everything is correctly configured.

On the virtual machine, I have two adapters, the defaulted NAT, without any port forwarding rule, and the usual vboxnet0 Host-only adapter. Such vboxnet0 host-only adapter has been created by going to File -> Host Network Manager, and adding a new entry. The DHCP server is disabled, and the IP address/mask is 192.168.56.101/24:

enter image description here

enter image description here

The ifconfig output from my virtual machine is:

enter image description here

and that's the contents of its /etc/network/interfaces:

enter image description here

The ifconfig output from my Host machine is:

enp61s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 00:d8:61:06:78:ce  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 2430  bytes 204819 (204.8 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2430  bytes 204819 (204.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vboxnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.56.101  netmask 255.255.255.0  broadcast 192.168.56.255
        inet6 fe80::800:27ff:fe00:0  prefixlen 64  scopeid 0x20<link>
        ether 0a:00:27:00:00:00  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 225  bytes 35362 (35.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlo1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.181.127.144  netmask 255.255.0.0  broadcast 10.181.255.255
        inet6 fe80::e7bf:1f7f:8578:e980  prefixlen 64  scopeid 0x20<link>
        ether 98:3b:8f:d8:06:17  txqueuelen 1000  (Ethernet)
        RX packets 90490  bytes 44130738 (44.1 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 15323  bytes 2985782 (2.9 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

and its etc/network/interfaces is the default one:

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

In the virtual machine, the ssh server is in start/running state and ufw is not blocking port 22:

enter image description here

However, from my host machine:

$ ssh -vvv 192.168.56.101
OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "192.168.56.101" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to 192.168.56.101 [192.168.56.101] port 22.
debug1: connect to address 192.168.56.101 port 22: Connection refused
ssh: connect to host 192.168.56.101 port 22: Connection refused

NOTE: Adding a port forwarding rule to the NAT adapter, unless I did it wrong, didn't solved the issue; besides, in my old laptop I have no port forwarding rules.

Peregring-lk

Yeahm as @Kenster said in a comment, both host and guest was assigned the same IP within the vboxnet0 network. I just deleted the vboxnet0 interface, and recreated again with the default options and DHCP server enabled. The virtual machine has already a static IP configured in /etc/network/interfaces so I don't need to further restrict the vboxnet0.

That way, with DHCP enabled, the host gets an IP (.1) different from the guest (the static .101) within the vboxnet0 network.

The connection refused error happened because, since the server IP matched the local IP, the client was trying to connect to localhost instead of to the virtual machine, and thus, since I don't have any ssh server installed, nobody was listening to port 22.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SSH to the Ubuntu host machine from a Ubuntu VirtualBox guest?

From Dev

SSH into VirtualBox Guest: Connection Refused

From Dev

Virtualbox guest additions on Ubuntu host and Manjaro guest

From Dev

How to copy & paste from Ubuntu VirtualBox guest to Windows host?

From Dev

Virtualbox: Mount a shared folder in Guest FreeBSD from Host Ubuntu

From Dev

Virtualbox: Mount a shared folder in Guest FreeBSD from Host Ubuntu

From Dev

How to copy & paste from Ubuntu VirtualBox guest to Windows host?

From Dev

Troubleshoot VirtualBox Linux Ubuntu guest access from Windows host

From Dev

Connecting to VirtualBox guest (ubuntu) from host (osx) via NAT?

From Dev

Run commands on an Ubuntu guest in VirtualBox VM from Windows host

From Dev

Virtualbox - how to passthrough modem from ubuntu host to windows guest

From Dev

Sharing existing ubuntu folder on host guest with Virtualbox

From Dev

Mac OS X as guest on VirtualBox with Ubuntu Host?

From Dev

VirtualBox Host ssh to Guest

From Dev

Virtualbox Ubuntu Guest Internet Connection - Any Ideas

From Dev

Can't reach tomcat server on Ubuntu 14.04 host from VirtualBox 4.3 Windows 7 guest or Ubuntu 14.04 guest

From Dev

Configuring VirtualBox host only networking: OSX host, Ubuntu guest

From Dev

GNOME Terminal: Connect via SSH from Ubuntu Desktop 14.04 into Ubuntu Server 14.04 Virtual Box Guest Host

From Dev

Can't connect via SSH from host Mac OS to guest Ubuntu: Host is down

From Dev

Accessing Ubuntu guest (VirtualBox) node.js server from Windows host

From Dev

Access Oracle 11g installed inside VirtualBox Guest from Ubuntu Host

From Dev

Can't access virtualbox guest's (ubuntu server) localhost from host's (windows) browser

From Dev

VirtualBox - guest Ubuntu loses DNS when host connects to VPN

From Dev

OEM license activation for Windows 10 Home VirtualBox guest, on Ubuntu host

From Dev

VirtualBox: host Windows 8.1 to guest Ubuntu first request response is slow

From Dev

Create a shared folder between Mac(Host) and Ubuntu(GUEST) on virtualbox

From Dev

Virtualbox Mac OSX host - Ubuntu guest is slow and laggy

From Dev

VirtualBox: USB Sticks not recognized (Windows XP as guest; Ubuntu 14.04 as host)

From Dev

keyboard works incorrectly for virtualbox ubuntu 15.04 guest in debian jessie host

Related Related

  1. 1

    SSH to the Ubuntu host machine from a Ubuntu VirtualBox guest?

  2. 2

    SSH into VirtualBox Guest: Connection Refused

  3. 3

    Virtualbox guest additions on Ubuntu host and Manjaro guest

  4. 4

    How to copy & paste from Ubuntu VirtualBox guest to Windows host?

  5. 5

    Virtualbox: Mount a shared folder in Guest FreeBSD from Host Ubuntu

  6. 6

    Virtualbox: Mount a shared folder in Guest FreeBSD from Host Ubuntu

  7. 7

    How to copy & paste from Ubuntu VirtualBox guest to Windows host?

  8. 8

    Troubleshoot VirtualBox Linux Ubuntu guest access from Windows host

  9. 9

    Connecting to VirtualBox guest (ubuntu) from host (osx) via NAT?

  10. 10

    Run commands on an Ubuntu guest in VirtualBox VM from Windows host

  11. 11

    Virtualbox - how to passthrough modem from ubuntu host to windows guest

  12. 12

    Sharing existing ubuntu folder on host guest with Virtualbox

  13. 13

    Mac OS X as guest on VirtualBox with Ubuntu Host?

  14. 14

    VirtualBox Host ssh to Guest

  15. 15

    Virtualbox Ubuntu Guest Internet Connection - Any Ideas

  16. 16

    Can't reach tomcat server on Ubuntu 14.04 host from VirtualBox 4.3 Windows 7 guest or Ubuntu 14.04 guest

  17. 17

    Configuring VirtualBox host only networking: OSX host, Ubuntu guest

  18. 18

    GNOME Terminal: Connect via SSH from Ubuntu Desktop 14.04 into Ubuntu Server 14.04 Virtual Box Guest Host

  19. 19

    Can't connect via SSH from host Mac OS to guest Ubuntu: Host is down

  20. 20

    Accessing Ubuntu guest (VirtualBox) node.js server from Windows host

  21. 21

    Access Oracle 11g installed inside VirtualBox Guest from Ubuntu Host

  22. 22

    Can't access virtualbox guest's (ubuntu server) localhost from host's (windows) browser

  23. 23

    VirtualBox - guest Ubuntu loses DNS when host connects to VPN

  24. 24

    OEM license activation for Windows 10 Home VirtualBox guest, on Ubuntu host

  25. 25

    VirtualBox: host Windows 8.1 to guest Ubuntu first request response is slow

  26. 26

    Create a shared folder between Mac(Host) and Ubuntu(GUEST) on virtualbox

  27. 27

    Virtualbox Mac OSX host - Ubuntu guest is slow and laggy

  28. 28

    VirtualBox: USB Sticks not recognized (Windows XP as guest; Ubuntu 14.04 as host)

  29. 29

    keyboard works incorrectly for virtualbox ubuntu 15.04 guest in debian jessie host

HotTag

Archive