2

I have an Ubuntu 20.04 VM (VirtualBox) on a Windows 11 host.

The network is attached by NAT.

I have port forwarding in VirtualBox as follows:

Name | Protocol |  Host IP    |  Host Port | Guest IP   |  Guest Port
SSH  |   TCP    |  127.0.0.1  |    2222    | 10.0.2.10  |     22

So now I can SSH to the VM from the Windows host via PuTTY from 127.0.0.1:2222 without any issues.

The IP of that host on my LAN is 192.168.10.15. So I try to ssh to that VM from another Windows PC via 192.168.10.15:2222 but I get Connection timed out.

So I thought perhaps the Windows host is blocking inbound traffic, so I opened all ports just in case (for testing) - connection still timed out.

So I added a port forwarding rule in my router on the IP 192.168.10.15 :

Name: SSH
External Port Start: 2200
External Port End: 2200
Protocol: TCP
Internal Port Start: 2222
Internal Port End: 2222
IPv4: 192.168.10.15

then I tried to SSH via 192.168.10.15:2200, but still nothing.

I even tried all sorts of combinations:

192.168.10.15:2222, 192.168.10.15:22, but all timed out.

I even added all ports to outbound rules on the Windows PC that tries to SSH to the other PC, still nothing

What is the problem?

1 Answer 1

0

Your router doesn't need a port forwarding rule if all you want is to connect to the host directly. You can just... connect to the host. The purpose of "port forwarding" is to translate addresses – e.g. when ssh'ing to the router's public (WAN) address, it would translate the destination to your computer's LAN address instead. But when you're already in the same LAN where you can directly say ssh 192.168.10.15, there is no translation involved. (In fact, a direct LAN connection doesn't even go through the router at all, so it couldn't apply port-forwarding if it wanted to.)

The real problem here is that the "Host IP" parameter in your VirtualBox's port forwarding rule only tells it to listen on 127.0.0.1 (loopback address). This means it will only accept connections made to 127.0.0.1 exactly – it doesn't matter that 192.168.10.15 is the same machine; the connection's destination address has to exactly match the listen address.

Change "Host IP" to 0.0.0.0 if you want it to listen on all IP addresses that the host machine has.

7
  • That worked! Btw, I changed 0.0.0.0 to only 192.168.10.15. Out of curiousity, in what scenario can a host has many IP addresses? I mean my host right now is a single PC that only needs to listen to 192.168.10.15
    – Stackerito
    Commented Mar 18, 2022 at 8:26
  • It's quite common. The first case is when the host has multiple network interfaces – even right now, your host has 192.168.10.15 on its Ethernet or Wi-Fi interface and 127.0.0.1 on the "loopback" interface (which would be invisible on Windows, but visible as lo in Ubuntu). If you had Wi-Fi and Ethernet connected, each would have its own address. You can configure the Ubuntu VM to have four virtual network interfaces (e.g. one NAT, one bridged, etc), and then it'd have 4 IPv4 addresses – or 5 if you count the lo interface with 127.0.0.1 on it. Commented Mar 18, 2022 at 8:30
  • Yes! thank you! (like when I type ipconfig I see the list of all network interfaces available and it's not just "my one pc"), you clarified everything, thank you!
    – Stackerito
    Commented Mar 18, 2022 at 8:32
  • The second case, just as common, is when a single interface has multiple IP addresses, which you can just add whenever you want. (On Windows this is only possible in "manual" configuration mode, not when DHCP is used – but if you set it to manual, then the "Advanced" window will let you add as many IP addresses as you want – e.g. the host could be 192.168.10.15 and 192.168.10.16 at the same time, each address potentially having different things listening on the same port.) This is very common on servers, which may have several IP addresses doing different things on the same system. Commented Mar 18, 2022 at 8:32
  • Thank you! That was an awesome explanation 😯
    – Stackerito
    Commented Mar 18, 2022 at 8:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .