The VirtualBox Virtual Machine network environment resolves and builds-NAT, bridging, Host-Only, Internal, and port ing. A few days ago, the teacher had to check the large job, while our databases are stored in virtual machines (we don't want to put too many things on the machine to keep them light and fast ...), the bridge mode is usually used, but considering the possibility that the Internet access is poor in the classroom (the signal below the library is poor ...), therefore, I tried to disconnect the network, but found that I could not connect to the database. Therefore, I found the network environment of the virtual machine. The information on the Internet was too complicated and I had to paste too many parties, therefore, this article is for your reference and future reference. All of them are tested and are not pasted. This article takes VirtualBox as an example. NAT Mode features: 1. If the host can access the Internet, virtual machines can access the Internet 2. virtual machines cannot be pinged between them 3. virtual machines can be pinged to the host (in this case, the gateway of the virtual machine is pinged to the host) 4. application scenarios where the host cannot be pinged to the virtual machine: virtual machines only require Internet access, no other special requirements, to meet the most common requirements configuration method: select Network Address Translation (NAT) as the connection method) advanced-control chip choose PCnet-fast iii advanced-hybrid mode reject advanced-access network cable √ (Virtual Machine ip automatically obtained) ip style: ip 10.0.2.15 gateway 10.0.2.2 note that the gateway here may be the same value in different virtual machines, but it belongs to different NAT engines. In fact, each virtual machine uses different gateway principles: requests from virtual machines are sent to the NAT Engine, which uses the host for external network access, and the returned packets are then sent to the Virtual Machine by the NAT Engine. Ii. Features of the Bridged Adapter mode (Bridge Mode): 1. If the host can access the Internet, virtual machines can access the internet. 2. virtual machines can be pinged between them. 3. virtual machines can be pinged to hosts. 4. The host can be pinged to the virtual machines. The preceding points are based on one premise: the host can access the internet. 5. If the host cannot access the Internet, all 1-4 features have no application scenarios: The Virtual Machine is required to access the Internet, and the virtual machine completely simulates the configuration of a physical machine: select the name of the bridge Nic interface (If your laptop has a wireless Nic and a wired Nic, select the name based on the current Internet access method) advanced-control chip choose PCnet-fast iii advanced-hybrid mode reject advanced-access network cable √ (Virtual Machine ip automatically obtained) ip style: the same principle between the ip address and the local ip address in the same CIDR block as that of the local Gateway: a bridge is established through the host Nic and connected directly to the network. It allows virtual machines to be allocated to independent IP addresses in a network. All network functions are the same as those of real machines in the network. (Virtual machines obtain IP addresses through the DHCP service in the network where the host is located. Therefore, they are completely independent, but in fact they do not have independent hardware, it still depends on the host's Nic. Therefore, if the host is disconnected from the network, the virtual machine cannot obtain the ip address ~~ All features disappear) 3. Host-only Adapter Mode features: 1. virtual machines cannot access the Internet. 2. virtual machines can be pinged between them. 3. virtual machines can be pinged to hosts. (Note that the communication between virtual machines and hosts is through the NIC named VirtualBox Host-Only Network of the Host, therefore, the ip address is the ip address 192.168.56.1 of the network adapter, rather than the ip address you are using to access the Internet.) 4. You can ping the VM on the host. application scenarios: when the host cannot access the Internet (host-only or bridging can be used when the host can access the Internet), you need to build a simulated lan. The configuration of mutual access between all hosts is as follows: select Host-Only as the connection method) select VirtualBox Host-Only Ethernet Adapter advanced for the Adapter interface name-select PCnet-fast iii for the control chip advanced for the control chip-reject advanced for the hybrid mode-access network cable √ (the Virtual Machine ip address is automatically obtained, you can also configure the gateway as the virtual network card of the host. Address [192.168.56.1 by default], and the ip address is configured as the ip address in the same CIDR block as the virtual NIC address.) ip Format: the ip address and the NIC ip address of the local VirtualBox Host-Only Network are in the same CIDR Block (192.168.56 by default. *) Network adapter ip address of the VirtualBox Host-Only Network on the gateway (192.168.56.1 by default) Principle: communication is performed through the VirtualBox Host-Only Network Nic. The virtual machine uses this ip address as the gateway, therefore, it simulates a LAN between the local machine and each virtual machine, as indicated by the name, it should be impossible to access the internet (but some people say that virtual machines can access the Internet by bridging the VirtualBox Host-Only Network adapter, but it is easier to directly use bridging, besides, I did not try it. Some people also said no, because the host does not provide the routing service, and I am not confused. You can try it yourself ~~) Iv. Features of Internal mode (intranet mode): 1. virtual machines cannot access the Internet. 2. virtual machines can be pinged between them. 3. virtual machines cannot be pinged to hosts. 4. Applications of virtual machines cannot be pinged to hosts: allow virtual machines to communicate with each other in an isolated LAN and isolate them from the external environment (including hosts). Configure the connection method by selecting the internal network interface name and intnet (you can rename the connection method, all virtual machines placed in the same LAN have the same name.) advanced-control chip: PCnet-fast iii advanced-hybrid mode: reject advanced-access network cable √ (Virtual Machine ip: for XP, You can automatically obtain the ip address, but for linux, you must manually configure the ip address and subnet mask. When manually configuring the ip address, you must ensure that the ip addresses of each virtual machine are in the same network segment.) ip address style: ip 169.254.147.9 subnet mask 255.255.0.0 Default Gateway no principle: each virtual machine uses the VirtualBox built-in DHCP server to obtain the ip address, packet transmission does not pass through the network of the host, so high security, prevent external packet capture ~ 5. NAT mode + port ing maps a port of the virtual machine to a port of the host, allowing the host and external machine to access the services provided by the virtual machine ~~ The command is as follows: (IN command line mode, first go to the VirtualBox installation directory; otherwise, the command cannot be found) vboxmanage setextradata <VM name> "VBoxInternal/Devices/pcnet/0/LUN #0/Config/<rule name>/Protocol" TCP vboxmanage setextradata <VM name> "VBoxInternal/Devices/ pcnet/0/LUN #0/Config/<rule name>/GuestPort "80 vboxmanage setextradata <VM name>" VBoxInternal/Devices/pcnet/0/LUN #0/Config/< rule name>/HostPort "8000