Requirement
The Linux server is installed in virtualbox, And the Linux server provides Web Services. The physical host is not connected to a vro or vswitch. The following requirements are available:
Preface
In Windows, virtualbox is used to virtualize a Linux Virtual Machine. Generally, the Network Mode of the Linux virtual machine is set to bridge mode. In this way, the Linux virtual machine is equivalent to an independent parallel existence with the PC, the two systems are in the same LAN and can ping each other. However, the premise is that the current PC is connected to a vro or vswitch. If two systems are in the same LAN without routers, switches, and other devices, the two systems cannot be pinged.
Now that the Linux virtual machine cannot use the bridge mode, set it to the NAT mode (Network Address Translation Nat. Nat Mode means that the virtual machine network is completely dependent on the network of the physical host. In this mode, the two systems do not process the same LAN and cannot directly ping the system. However, virtualbox can set port forwarding rules in Nat mode. By setting rules, the PC can connect to virtual machines in virtualbox.
Practice
Open virtualbox, right-click the Linux virtual machine, and select Settings. In the device panel, selectNetwork
, Nic 1 connection mode isNetwork Address Translation Nat
, ClickAdvanced
To display advanced settings, such:
ClickPort forwarding
Click to open the port forwarding rule list. You can add or delete rules.
Some Terms in the Rules are described as follows:
HOST: Physical host system.
Subsystem: A system virtualized by virtualbox.
Host port: the port of the physical host system, which is forwarded to the subsystem port.
Subsystem port: the port of the Virtual Machine subsystem.
The following describes how to add an SSH connection rule.
Click the green plus sign on the right to add a rule to the rule list. Change its namessh
(This name can be written as needed ). Protocol selectionTCP
.Host IP Address
AndSubsystem IP Address
Leave it blank.Host Port
Enter2222
Can also be changed to another port, as long as it does not conflict with other ports, the physical host will use this port when connecting to the virtual machine through SSH.Subsystem Port
Enter22
Because SSH connections use port 22 by default, this cannot be entered at will. For example, if the most common protocol is HTTP, port 80 is used by default, and port 21 is used by default for FTP connections. After entering the information, clickOK
Button to save the settings.
Open the Linux virtual machine, install and enable the SSH service, and disable the firewall. In Windows, you can use putty or securecrt to connect to a Linux virtual machine.localhost
Or127.0.0.1
Enter the port in the port forwarding rule set in virtualboxHost Port
In the preceding example2222
. If the connection fails, check whether the Linux virtual machine has been installed and enabled for the SSH service, and disable the firewall.
I installed Apache and vsftp on a Linux Virtual Machine and set virtualbox port forwarding rules, as shown in. In Windowslocalhost:8008
Or127.0.0.1:8008
You can access the Web page throughlocalhost:2121
Or127.0.0.1:2121
You can connect to FTP.
Command Line
As mentioned above, port forwarding rules are directly set on the graphical interface, and commands are also used.
Open CMD and locate your virtualbox installation directory, for example, "C: \ Program Files \ oracle \ virtualbox ". For example, the name of my Linux Virtual Machine in virtualbox isUbuntu
To add ssh port forwarding rules in the preceding example, enter the following command:
1 |
VBoxManage modifyvm "Ubuntu" --natpf1 "ssh,tcp,,2222,,22" |
The command is parsed as follows:
1 |
Vboxmanage modifyvm "Linux Virtual Machine name" -- natpf1 "rule name, protocol, Host IP address, host port, subsystem IP address, subsystem port" |
Reference