Question: I have a computer running a virtual machine using NAT on VirtualBox, virtual chance of being assigned a private IP address (10.x.x.x) VirtualBox. If I want to SSH from the host to the virtual machine, how can I do?
VirtualBox virtual machine network supports several different ways, one of which is the NAT network. When the virtual machine enabled NAT, VirtualBox will automatically between the virtual machine and the host network translation, so you do not have to configure anything between the virtual machine and the host. This also means that NAT in the virtual machine to an external network and host itself is not visible. This will be when you want to access the virtual machine from the host will cause problems (such as SSH).
If you want the virtual machine from the VirtualBox NAT environment, you can enable the VirtualBox NAT port forwarding in the GUI or the command line. This tutorial will demonstrate how to connect to the NAT and the environment by enabling the client to forward port 22 from the host SSH. If you want to access NAT's first client from HTTP, use port 80 instead of 22 port.
VirtualBox port forwarding through the GUI configuration
Select the virtual machine you want to access in VirtualBox, open the virtual machine's "Settings." Click on the left side of the "Network" menu, click on the network adapter option "Advanced."
Click "Port Forwarding" button
You will see a window to configure port forwarding rules. Top right, click "Add" icon.
We would like to see that kind of forwarding rules.
Name: SSH (can be any unique name)
Host IP: 127.0.0.1
Host Port: 2222 (any unused port greater than 1024)
Guest IP: IP Virtual Machine
Guest Port: 22 (SSH port)
Port forwarding rules automatically when you start the virtual machine enabled. In order to verify. After you can enable the virtual machine to check whether port 2222 is turned on VirtualBox.
$ Sudo netstat -nap | grep 2222
Now you can use port forwarding, you can use the following command SSH to the virtual machine.
$ Ssh -p 2222 < login> @ 127.0.0.1
Sent to the login request 127.0.0.1:2222 it will be automatically translated into VirtualBox 10.0.2.15:22, which allows you to SSH into the virtual machine.
By command VirtualBox port forwarding
VirtualBox has a command-line management tool called the VBoxManage. Using the command line tool, you can also be forwarded to your virtual machine port settings.
The following command is the IP address for the virtual machine 10.0.2.15 set a name for the "CentOS7" port forwarding rule, SSH port number is 22, mapped to the local host port 2222. Rule name (in this case, SSH) must be unique.
$ VBoxManage modifyvm "centos7" - natpf1 "SSH, tcp, 127.0.0.1,2222,10.0.2.15,22"
After the rule is created, you can use the following command to verify.
$ VBoxManage showvminfo "centos7" | grep NIC