Accessing VirtualBox with NAT adapter using SSH

3

1

I have a CentOs 6.5 running on a VirtualBox. I am using NAT adapter and my inet addr is 10.0.2.15 But, I can't access this host using ssh root@10.0.2.15 I get ssh: connect to host 10.0.2.15 port 22: Bad file number error.

Is there anyway to access a server using NAT adapter using ssh from putty?

Bimlik

Posted 2014-04-06T21:45:51.480

Reputation: 87

Ensure you have a functioning SSH server running on the host machine and ensure your port 22 is forwarding onto the internal IP of the host. If these are configured correctly you can SSH from guest to host. – Matthew Williams – 2014-04-06T21:49:01.487

@MatthewWilliams All my settings are described here My port is 8080. That means, currently I am able to log in using 127.0.0.1:8080 but unfotunately I can't access thought ssh with this settings

– Bimlik – 2014-04-06T21:52:00.790

Answers

4

Add another port forward to virtualbox with:

Host IP 127.0.0.1 Host Port 2222 Guest IP 10.0.2.15 Guest port 22

Then ssh to port 2222 on 127.0.0.1

Rinse and repeat for any other ports required, remembering that the port cannot be <1024 on the host side.

metacom

Posted 2014-04-06T21:45:51.480

Reputation: 176

How on earth do you send a port forward onto a loopback address? All you will get here is a timeout from your router. – Matthew Williams – 2014-04-06T21:57:00.043

@MatthewWilliams It seems like he is right. I worked like a charm. I am able to access it now. – Bimlik – 2014-04-06T22:00:23.637

It's on the virtual box side with a NAT setup; it is counter intuitive, but it works. The loopback in this case is the host machine's loopback, which can talk to the guest machine via it's NAT'd ip. – metacom – 2014-04-06T22:00:27.417

This seems very strange, but if it works I suppose.... – Matthew Williams – 2014-04-06T22:04:38.510

@metacom Unfortunately, things are a bit worse when it comes to sharing folders. I used to use samba to share foders between virutual box and Windows 7. Now, I am unable too. Any way to remedy this problem? – Bimlik – 2014-04-07T12:30:19.777