0

I am connecting to a server via ssh -L 8000:localhost:8000 <hostname> on my Ubuntu virtual machine in VirtualBox. In the VM, I can access the server via "localhost:8000" but cannot from the IP address "192.168.11.175:8000" (I have a bridged adapter). I cannot access the server in my host OS (Windows 10) via localhost or the IP. How could I get access to the VM localhost from my host machine?

Results from running ifconfig:

enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 192.168.11.175  netmask 255.255.255.0  broadcast 192.168.11.255
    inet6 fe80::61a3:b162:4e6e:4731  prefixlen 64  scopeid 0x20<link>
    ether 08:00:27:30:85:c2  txqueuelen 1000  (Ethernet)
    RX packets 4097  bytes 3519328 (3.5 MB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 3347  bytes 551359 (551.3 KB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
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 2179  bytes 1877351 (1.8 MB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 2179  bytes 1877351 (1.8 MB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

VM Info

2 Answers 2

1

One to achieve this is to ssh into your Ubuntu VM from the "host" (your Windows 10 machine) using -L (for local port forwarding) as well.

You chose Windows as your host for some reason, so there is no built-in ssh command as in macOS, Linux etc.

So I assume you're probably using tools like PuTTY?

You can set up local port forwarding in PuTTY using its config dialog - find more information i.e. here.

After having forwarded port 8000 from your Windows host to the Ubuntu VM, it will then be further forwarded through the ssh -L ... command you mentioned to the remote server.

1
  • I believe this would be the route to go. It ended up being more trouble than it was worth. The reason I wanted to access the VM localhost on my host machine was because the VM was not very responsive. I discovered I was able to easily fix that issue by giving it more CPU cores. Commented Jun 15, 2020 at 16:38
1

ssh -L 8000:localhost:8000 <hostname> means the same as ssh -L localhost:8000:localhost:8000 <hostname>

Long story short, the first localhost:8000 is on client side (Win 10 in your case) and the second one is on server side.

Flag -L means to open port on the client side. So all you need after connection established successfully is to go on http://localhost:8000 on your Windows 10 host

Update:

If you want to use 192.168.11.175:8000 please check at first if your server is binded to this address or to 0.0.0.0:8000.

If it listens localhost:8000 or 127.0.0.1:8000, then it's not possible to connect through the network.

You can check all binded TCP ports with the following command:

sudo netstat -46lnp

Flag p here (requires sudo) enables column with program name.

You must log in to answer this question.

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