If you want:
- a Linux guest runnning on a Windows host
- the ability to ssh to the guest from the Windows host
- the ability to ssh to the guest from another machine on your home network
About 90% of this comes from: https://gist.github.com/pjdietz/5768124 just with a few fixes for the host only network
1 Create a host only network in the Virtualbox GUI
- File -> Preferences -> Network -> Host-Only Networks (tab) ->
+
icon
Make note of the network IP address in the GUI, for example: 192.168.99.1
2 Create a new VM and install Ubuntu Server (tested with 16.04.2)
In the machine settings you should add the Host-only adapter
- Settings -> Network -> Adapter2 -> Attached to: (select Host-only Adapter) then select the Host only network you just created
Do not select DHCP, we want the guest to assign a static ip
3 Make sure sshd is installed and running
After installation you should double check that sshd is running sudo service sshd status
If not installed sudo apt install sshd
, it should start on port 22
4 Configure static host only interface
If you ifconfig
vs ifconfig -a
you will notice that one interface extra is listed but it's not up and has no IP.
Make note of this interface name, example: enp0s8
or eth1
sudo nano /etc/network/interfaces
Add the following configuration
# The host-only network interface
auto enp0s8
iface enp0s8 inet static
address 192.168.99.2
netmask 255.255.255.0
network 192.168.99.1
Remember to replace these two things
192.168.99.1
with the value of the host-only network IP from the virtualbox GUI192.168.99.2
with a invented IP address on that subnet, simply picking something besides 1 and 255 will do (that is where the.2
comes from)
Now sudo reboot
When the machine comes up ifconfig
and see if the interface has everything applied
You should be able to test by sshing or telnetting to the host only ip
5 Port forwarding from host to guest
Port forwarding is setup in the Vbox machine settings Network tab again.
This time, select Apdapter 1, the NAT adapter, and unfold Advanced, click Port Forwarding
On your guest ifconfig
again and make note of the other interface, it will probably have an ip like 10.0.2.15
Create a new port forwarding rule. Security note: this will expose a port on your home network directly to the Vbox ssh port, so be aware of those consequences.
Protocol: TCP
Host IP: 0.0.0.0
Host Port: 2222
Guest IP: 10.0.2.15
Guest POrt: 22
Make sure to replace your Guest IP with the NAT ip.
6 🍺
Now from another machine on your network like your shitty chromebook you should be able to:
ssh -p 2222 user@HOSTIP
Where HOSTIP is the ip of the host running the VM on your home network.
This is a dream setup for me at home.
For some reason ifconfig and ifconfig -a were giving me the same output. I assumed enp0s8 was the one that needed to be added since you have it here as well. It is working like a charm, thank you:)