Original: Curly brace MC(wechat official account: Huakuohao-MC), welcome to share, please keep the source.
I believe that every programmer will have the need to use virtual machines, because in daily work and learning, many problems need to be carried out in the cluster environment, such as Mysql cluster, Redis cluster, Hadoop cluster, Spark cluster, K8S cluster and so on.
Without the help of virtual machines, the wallet is really unbearable, after all, renting a cloud host for daily learning is not affordable. Common Virtual software include Vmware and Virtual Box.
Vm network requirements
Creating virtual machines is not a problem for many people, but how to choose the right network mode is confusing for many people. Especially for students who need to set up a cluster environment, VMS created by themselves can access each other. VMS can access the public network for software installation, and hosts can access VMS.
In view of the above actual network demands, let’s look at the Virtual machine created by Virtual Box, how to correctly choose the network model.
Classification of common network modes
- NAT network
- Network Address Translation (NAT)
- Bridged Adapter
- Host-only network
- Internal network
NAT network
The NETWORK address translation (NAT) technology enables VMS to have their own internal IP addresses, and VMS use the host as a gateway. Therefore, VMS can Ping hosts and access the public network. However, VMS cannot be pinged from the host or from each other.
Network Address Translation (NAT)
All features are the same as NAT networks. The only difference is that port forwarding rules can be configured to enable the host to access VMS.
Bridged Adapter
When a VM connects to the host network through the host nic, the VM obtains an IP address on the same network segment as the host. Therefore, VMS to hosts, hosts to VMS, and VMS to the public network can Ping each other. Disable the firewall.
Host Only network
A Virtual Box creates a Virtual network interface card (NIC) in the host computer. This NIC is used by all VMS. That is, all VMS use the IP address of the network adapter to create subnets. The VIRTUAL NIC and the host NIC are in different network segments. Therefore, by default, the VM cannot communicate with the host, and the VM cannot access the public network. However, VMS can communicate with each other because they are all on the same network segment. However, in this mode, VMS can communicate with hosts and the public network through nic sharing and bridging.
Internal network
As the name implies, the network is only used within VMS, and VMS can communicate with each other. VMS cannot communicate with hosts or with the public network.
Summarize the interoperability of the above centralized network modes in a table:
Access to the direction | NAT | NAT forwarding | Bridge (Bridged Adapter) | Host Only | The internal network |
---|---|---|---|---|---|
Host -> Virtual machine | no | yes | yes | The default value is no, and the default value is yes | no |
Virtual machine -> Other hosts | yes | yes | yes | The default value is no, and the default value is yes | no |
Other hosts -> Virtual machines | no | yes | yes | The default value is no, and the default value is yes | no |
Virtual machine -> Virtual machine | no | no | yes | yes | yes |
Network Scheme selection
From the table above, we can see that both the bridge and host-only modes satisfy our requirements. What is the difference between the two modes?
- Bridge mode, assigned by the virtual machine
IP
And the host machineIP
They are on the same network segment. If in the company, the general corporate network segment is allocated staticIP
If your VIRTUAL machine occupies the host network segmentIP
, the company network administrator will probably talk to you. But using it in your own home is less of a problem. - Host-only mode. After host-only mode is configured, the VM has its own internal network segment and does not occupy the Host
IP
Resources. Therefore, this scheme is still recommended, although the configuration may be a bit more complicated than the bridge mode.
In addition to the preceding two methods, you can also configure two nics for a VM. Nic 1 uses NAT to enable the VM to access the public network, and NIC 2 uses host-only to enable the VM to access each other.
conclusion
If you want to deeply understand the working principle of each network mode, you should learn network knowledge systematically. Build a virtual machine, learn and experiment.
Recommended reading
1. Java concurrent programming stuff (10) — Final summary
2. Talk about symmetric and asymmetric encryption
3. Do you know how to use Awk
4. Teach you how to build a set of ELK log search operation and maintenance platform
Original: Curly brace MC(wechat official account: Huakuohao-MC) Focus on JAVA basic programming and big data, focus on experience sharing and personal growth.