0
  • VirtualBox version: 6.0.6
  • Host OS: Windows 10
  • Guest OS: Ubuntu 18.04

How can I VM so that I can SSH into VM from another server outside LAN?

I have tried using NAT adapter and port forwarding, Bridged adapter and Host-Only settings but every time I try to SSH into my VM it responds with error.

ssh: ... Connection timed out

I have no problem to SSH into VM from my own computer using SSH.

4
  • 1
    Similar Questions have been Answered before : superuser.com/questions/424083/virtualbox-host-ssh-to-guest . Commented May 15, 2019 at 19:22
  • Hi, and welcome to SuperUser. It is going to be really hard to determine why it is not working, because it can go wrong at many stages. From firewalls with whitelists to improper port forwarding. If you set it to bridged, it will push the server into the LAN like your own pc. If at that point it still doesn't work, then the necessary ports are not open, or you are simply not accessing it through the right IP. Remember that when you switch to bridged, it will get an IP from the DHCP server in your network, so the IP changes.
    – LPChip
    Commented May 15, 2019 at 19:46
  • @LPChip Yes, currently I have set to Bridged adapter and I have also added a firewall rule that allows port 22. And I'm pretty sure that IP i'm using is correct. Since I can ssh into my VM from host.
    – j.dawg
    Commented May 15, 2019 at 20:06
  • 2
    On your router, you need to port forward 22 to the IP of the VM inside your network.
    – uSlackr
    Commented May 15, 2019 at 20:54

1 Answer 1

0

@j.dawg

Same problem for me.

Definitely the case @Christopher Hostage mentioned is quite common but not what I am aiming for.

i.e. I need to let a computer outside the LAN to access the linux VM that is inside a host (windows) that is inside the LAN.

Here is my short answer to this question, refer to this brilliant article by Michel Blancard:

One approach is config the router or NAT gateway of the LAN:

  • use DMZ in router to expose the VM. (risky: only if you are confident to expose this VM to outside world)
  • A Better way is to use Port Mapping.

Another approach is tunneling

  • Commertial services
  • Or SSH remote port forwarding to an enabled SSH server.

Some detail for my adopted solution (more detail please check the article)

SSH remote port forwarding

Make sure that the following options are set in the /etc/ssh/sshd_config of the remote server and reload the SSH server if needed:

AllowTcpForwarding yes
GatewayPorts yes

Set up remote port forwarding (the tunnel) from the local workstation:

ssh -nN -R 8888:localhost:8889 [email protected]

Here :

  • 1.2.3.4 is the public IP address of the remote server
  • 8888 is the port the server is listening to
  • 8889 is the port of your workstation that you want to expose
  • remoteuser is the name of a user that has the right to connect to the server using ssh
  • -n prevents reading from stdin, because you don’t want to use the tunnel from the command line
  • -N means that you do not want to execute remote commands, just do port forwarding
  • -R (as Reverse or Remote port forwarding) means that the connections are forwarded from the remote server to your local workstation, instead of port forwarding where the end that initiates the tunnel is also the one that initiates the communications across the tunnel.
  • optionally, you can use a specific ssh key instead of the default ~/.ssh/id_rsa : -i ~/.ssh/id_rsa_2

Test

Listen on the destination port of the workstation :

netcat -l -p 8889

Send message from anywhere in the world :

echo “abc” | nc -v remoteserver 8888

You should receive “abc” in your workstation’s terminal.

Troubleshooting

If the message is not properly conveyed, the verbose option of the ssh client (-v) is of great use. You can also verify that everyone is listening as expected using netstat:

netstat -pln
1
  • For your ssh timeout, the best way is first try to troubleshooting with (-v) option. or (-vvv). Commented Mar 13, 2020 at 4:14

You must log in to answer this question.

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