Unable to ssh into Ubuntu VM running w/ a NAT ip address even w/ openssh-server installed
This is a fresh install of Ubuntu Server 12.10 running VirtulBox 4.8.2 on a Kubuntu 12.10 host. I have Ubuntu Server running w/ a NAT'ed IP Address (10.0.2.X or something like that). I want to ssh from my Kubuntu laptop to my VBox server so during install I selected OpenSSL Server or whatever the option is. Outside of that selection there is nothing custom done and the system is completely up to date.
So when I try to ssh to that device I get a timeout response and am unable to connect. The service is running on my VM but nothing happens. I also cannot ping the VM either.
Is there something I'm missing? A firewall between my VM and Host? Not quite sure
Thanks for the help in advance,
Jonathan
The problem is the NAT. When you are using NAT, VirtualBox basically acts like a router making a subnet, and just like with a normal Router setup you can't access a device on a lower subnet. As I see it you have two options here:
Switch your VM to a "Bridged Adapter" mode(can be done even after an OS is installed) and then Reboot or Renew your Server's IP. Your VM should show up with a normal IP on your Network and then you can easily access it. I usually recommend this for Servers anyway because burying a Server defeats the use of one.
Make a Reverse SSH Tunnel. Basically instead of making a tunnel from your Host to the Guest Server, you do it the other way around. This is a pretty straight forward task and there's a nice HowTo to be found here: http://www.howtoforge.com/reverse-ssh-tunneling, Just use your Host's normal network IP and it should work. A user also posted a nice thing in the comments of the article about SSH Tunnels between 2 PCs with both being behind NATs.
Out of the above I still recommend #1 for obvious advantages to a server setup but if you really want to keep the Server Sandboxed then #2 should work fine.
You can of course also use port forwarding in virtual box:
- Go to the VM settings
- Select network
- Click Port Forwarding
- Fill out a row
- Give a useful name like 'SSH'
- Leave protocol as TCP
- Set Host IP as the host IP (eg: 127.0.0.1)
- Set Host Port as something like 10022
- Set Guest IP as the IP of the VM
- Set Guest port as 22 (or the SSH port)
- Connect to the host details (eg: 127.0.0.1:10022)