0

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.

  • 1
    It looks like 192.168.56.101 is assigned to both the host and the guest. The host and the guest should have different IP addresses for their host-network interfaces. Try setting the host adapter's address (from the first image) to 192.168.56.10 or something else less than 100. If that doesn't work, please edit your question to mention how the guest gets its IP address, and include the DHCP server configuration for the host-only network if it's relevant. – Kenster Dec 6 '19 at 18:08
  • But the 192.168.56.101 IP is the vboxnet0 interface created by virtualbox. I don't think that can be changed. – Peregring-lk Dec 6 '19 at 18:11
  • @Kenster The problem could be related to what you said. If I tail -f both auth.log or syslog, there are no new messages in any of both log files, so it seems that the client is trying to connect to localhost and, since my host machine has of course no ssh server, the connection is refused. – Peregring-lk Dec 6 '19 at 18:28
1

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.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.