Page 1 of 1

How to ssh into a guest using NAT?

PostPosted: 30. May 2013, 00:15
by murphyc
From the OS X Terminal, I want to ssh into a Fedora Linux guest running in a VirtualBox VM. Previously I've done this by setting the guest Network panel's Attached To pop-up panel to Bridged. This causes the VM to get its own IP address assigned by the network DHCP router. However, the current network I'm on doesn't support this, it will only assign one IP per wireless connection. Setting Attached To to the default of NAT allows network connectivity to work, but now I can't ssh into the VM.

Guest OS link enp0s3 has an IP address of 10.0.2.15/24

Host OS link en1 has an IP address of 192.168.21.121 which isn't on the same subnet.
Host OS link vboxnet0 doesn't have an IP address assigned. With qemu-kvm, I'm used to the virtual link having an IP address as well, and it is possible to ssh into the guest set to NAT. I can't figure out an equivalent for VirtualBox.

Host OS X 10.8.3, VirtualBox 4.2.12.
Guest Fedora Linux 18 (or 19 beta), VirtualBox guest Network panel is Attached To: NAT (default) using the wireless connection.

Re: How to ssh into a guest using NAT?

PostPosted: 30. May 2013, 00:32
by murphyc
Aha. Maybe there's another way to do this, but in VirtualBox, VM's Network panel, click on advanced, click on Port Forwarding button. In there set up a rule:

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

Then enable ssh in the guest, and I'm able to connect from the host using:

ssh -p 2222 root@127.0.0.1

I haven't tried it because I don't have a 2nd computer, but I think ssh -p 2222 root@192.168.21.121 would also work.

Re: How to ssh into a guest using NAT?

PostPosted: 30. May 2013, 00:33
by Perryg
Add a second adapter set to host-only or use port forwarding in NAT.
See http://www.virtualbox.org/manual/ch06.h ... k_hostonly & http://www.virtualbox.org/manual/ch06.html#natforward

Special note: Post forwarding can be done in the VirtualBox main manager. (click advanced in the network settings)