Because a few days ago the teacher to check the big homework, and our database is placed in the virtual machine (do not want to put too many things in this machine, keep light and fast ...) ), usually used in the bridge mode, but given the possibility of the classroom is not good online (the library under the poor signal ...) ), so I tried to break the network, but found that can not connect to the database, so specialized to find data to learn about the virtual Machine network environment, online information more miscellaneous, paste party too much, hurt me, so write this article for everyone's reference, also for their future reference. It's all tested, not pasted.
This paper takes VirtualBox as an example
If a host cannot ping the virtual machine, first make sure that the virtual machine firewall is turned off.
First, Nat mode
Characteristics:
1. If the host can surf the Internet, the virtual machine can surf the internet
2, the virtual machine can not ping through
3, the virtual machine can ping the host (at this time, ping virtual machine gateway, that is ping host)
4, the host can not ping the virtual machine
Application Scenario:
Virtual machines only require access to the Internet, no other special requirements to meet the most general needs
Configuration method:
Connection mode Select Network Address translation (NAT)
Advanced-Control chip selection Pcnet-fast III
Advanced-Promiscuous mode rejection
Advanced-access Network cable √
(Virtual machine IP automatic acquisition)
IP style:
IP 10.0.2.15
Gateway 10.0.2.2
Note that the gateways here may be the same value in different virtual machines, but this belongs to a different Nat Engine, so that virtually every virtual machine is not using the same gateway
Principle:
The request of the virtual machine is passed to the NAT Engine, which uses the host for external network access, and the returned packet is Engine by NAT to the virtual machine.
Second, bridged adapter mode (bridging mode)
Characteristics:
1. If the host can surf the Internet, the virtual machine can surf the internet
2, the virtual machine can ping through
3, the virtual machine can ping through the host
4, the host can ping the virtual machine
The above points are based on the premise that the host can surf the internet
5, if the host can not access the Internet, all 1-4 features are not
Application Scenario:
Virtual machines require access to the Internet, and virtual machines completely simulate a solid machine
Configuration method:
Connection mode select Bridging network card
Interface Name selection (if your notebook has a wireless card and a wired network card, you need to choose according to the current way of the Internet)
Advanced-Control chip selection Pcnet-fast III
Advanced-Promiscuous mode rejection
Advanced-access Network cable √
(Virtual machine IP automatic acquisition)
IP style:
IP and native IP in the same network segment
The gateway is the same as the native gateway
Principle:
Through the host network card, erecting a bridge, directly connected to the network. It allows the virtual function to be assigned to a network of independent IP, all network functions completely and
The same as the real machine in the network.
(The virtual machine gets the IP address from the DHCP service on the host's network, so logically, the two are completely independent, but the fact is that the virtual machine is not
Have independent hardware, it is still to rely on the host network card, therefore, the host to disconnect the network, virtual machines will not be able to get IP, so hehe ~ ~ All characteristics of the whole
Disappeared)
Three, host-only adapter mode
Characteristics:
1, the virtual machine can not access the Internet
2, the virtual machine can ping through
3, the virtual machine can ping the host (note that the virtual machine and host communication is through the host named VirtualBox host-only Network network card, so IP is the network card IP 192.168.56.1, rather than you are now using the Internet IP)
4, the host can ping the virtual machine
Application Scenario:
When the host is unable to access the Internet (the host can access the Internet can use Host-only, can also use bridge), need to build an analog LAN, all machines can exchange visits
Configuration method:
Connect mode Select Host only (HOST-ONLY) adapter
Interface Name Selection VirtualBox host-only Ethernet Adapter
Advanced-Control chip selection Pcnet-fast III
Advanced-Promiscuous mode rejection
Advanced-access Network cable √
(Virtual machine IP automatic acquisition, can also be configured, the gateway configured as the main machine in the Virtual network card address "default for 192.168.56.1", IP configuration and virtual network card address with the same network segment address)
IP style:
IP and native VirtualBox host-only network network card IP is within the same network segment (default 192.168.56.*)
Network Guan Ben VirtualBox host-only Network network card IP (default 192.168.56.1)
Principle:
Through the VirtualBox host-only Network network card communication, the virtual machine with this IP as a gateway, thus simulating a local and individual virtual machine LAN, as the name implies,
should be unable to access the Internet (but it is said that the VirtualBox host-only Network network card can be bridged and other operations to make the virtual machine can access the Internet, but this is not as direct
The use of bridges to the easy, and, oh, I did not try to succeed, some people also said not, because the host does not provide routing services, I am also not good at the end of the chaos, you try it ~ ~)
Four, internal mode (intranet mode)
Characteristics:
1, the virtual machine can not access the Internet
2, the virtual machine can ping through
3, the virtual machine can not ping through the host
4, the host can not ping the virtual machine
Application Scenario:
Allow each virtual machine to be in an isolated LAN, allowing them to communicate with each other, isolated from the outside world (including the host)
Configuration method:
Connect Mode Select Internal Network
Interface Name Select Intnet (can be renamed, all the virtual machines placed on the same local area network this name is the same)
Advanced-Control chip selection Pcnet-fast III
Advanced-Promiscuous mode rejection
Advanced-access Network cable √
(Virtual machine IP: For xp automatically get IP, but for Linux, you must manually configure the IP and subnet mask, manual configuration to ensure that each virtual machine IP in the same network segment)
IP Style:
IP 169.254.147.9
Subnet Mask 255.255.0.0
Default Gateway None
Principle:
Each virtual machine uses VirtualBox built-in DHCP server to get IP, packet transmission does not go through the host network, so the security is high, to prevent external grab bag ~
Five, Nat mode + port mapping
Mapping a virtual machine port to a host port allows the host and external machines to access the services provided by the virtual machine Oh ~ ~
The order is as follows:
(in command line mode, first 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
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.