VirtualBox virtual machine network environment analysis and build NAT bridge Host Only Internal port mapping

  • 2020-05-27 07:51:43
  • OfStack

Since the teacher had to check the big homework a few days ago, our database is in the virtual machine (don't want to put too much stuff in the machine, keep it light and fast...). "Is usually used in the bridge mode, but considering the possibility of poor Internet access in the classroom (poor signal under the library...). , so I tried to break the network, but found that can not be connected to the database, so I specifically found the information to learn 1 virtual machine network environment, online information is more miscellaneous, paste party too much, hurt me, so write this article for your reference, but also for their own reference in the future. It's all tested, not pasted.

This article takes VirtualBox as an example

If the host cannot connect ping to the virtual machine, please first confirm that the fire wall of the virtual machine is closed.

1. NAT mode

Features:

1, if the host can surf the Internet, the virtual machine can surf the Internet

2. No ping connection is allowed between virtual machines

3. The virtual machine can connect ping to the host (at this time, the gateway of ping virtual machine is ping host)

4. The host cannot use the virtual machine ping

Application scenarios:

Virtual machine only requires Internet access, no other special requirements, to meet the most common needs

Configuration method:

Select network address translation (NAT)

Advanced - control chip selection PCnet-FAST III

Advanced - hybrid mode rejected

Advanced - access line √

(virtual machine ip automatic fetch)

ip style:

ip 10.0.2.15

The gateway 10.0.2.2

Note that the gateway here may have the same value in different virtual machines, but this belongs to a different NAT Engine, so in fact each virtual machine does not use the same gateway

Principle:

The request from the virtual machine is passed to NAT Engine, which makes use of the host to access the external network, and the returned packet is then sent to the virtual machine by NAT Engine.

2. Bridged Adapter mode (bridge mode)

Features:

1, if the host can surf the Internet, the virtual machine can surf the Internet

2. Virtual machines can be connected with ping

3, the virtual machine can be ping through the host

4. The host can use ping virtual machine

Each of the above points is based on one premise: the host can access the Internet

5, if the host can not access the Internet, all 1-4 features are not available

Application scenarios:

Virtual machine requirements can be connected to the Internet, and virtual machine fully simulate 1 physical machine

Configuration method:

Select the connection mode to bridge the network card

Interface name selection (if your laptop has a wireless network card and a wired network card, you need to choose according to the current Internet access mode)

Advanced - control chip selection PCnet-FAST III

Advanced - hybrid mode rejected

Advanced - access line √

(virtual machine ip automatic acquisition)

ip style:

ip and native ip are in the same network segment

The gateway is the same as the native gateway

Principle:

Through the host network card, set up a bridge, directly connected to the network. It enables virtual functions to be assigned to a separate IP within a network, with all network functions fully integrated

Real machine 1 in the network.

(the virtual machine gets the ip address from the DHCP service on the network where the host is located, so the two are supposed to be completely independent, but the reality is that the virtual machine is not

Have independent hardware, it still depends on the host network card, therefore, the host to disconnect the network, the virtual machine can not get ip, so ha ha ~~ all features are complete

Disappear!)

3. Host-only Adapter mode

Features:

1. The virtual machine is not allowed to surf the Internet

2. Virtual machines can be connected with ping

3, the virtual machine can ping to the host (note that the virtual machine communicates with the host through the host's network card named VirtualBox Host-Only Network, so ip is the network card ip 192.168.56.1, not the ip you are using now)

4. The host can use the virtual machine ping

Application scenarios:

In the case that the host cannot access the Internet (host-only or bridge can be used if the host can access the Internet), it is necessary to set up a simulated LAN and all the machines can visit each other

Configuration method:

Select host only (Host-Only) adapter for connection

Select VirtualBox Host-Only Ethernet Adapter

Advanced - control chip selection PCnet-FAST III

Advanced - hybrid mode rejected

Advanced - access line √
(the virtual machine ip is automatically acquired, and can also be configured by itself. The gateway is configured as the address of the virtual network card in the host (default is 192.168.56.1), and ip is configured as the network segment address of the virtual network card)

ip style:

ip and VirtualBox Host-Only Network's network card ip are in the same network segment (default: 192.168.56.*)

Gateway native VirtualBox Host-Only Network network card ip (default 192.168.56.1)

Principle:

VirtualBox Host-Only Network network card is used for communication. The virtual machine USES ip as the gateway. Therefore, it simulates a local area network between this machine and each virtual machine.

It should not be able to access the Internet (but some people say you can bridge the VirtualBox Host-Only Network network card to enable the virtual machine to access the Internet, but that's not as straightforward as that

The bridge is easy to use, and, oh, I didn't try to succeed, some people also said no, because the host does not provide routing service, I am not good to say whether it is ok, you try it yourself ~~)

4. Internal mode (Intranet mode)

Features:

1. The virtual machine is not allowed to surf the Internet

2. Virtual machines can be connected with ping

3, the virtual machine can not ping host

4. The host cannot use the virtual machine ping

Application scenarios:

Keep each virtual machine in an isolated LAN and only let them communicate with each other, isolated from the outside world (including the host)

Configuration method:

Select the internal network connection mode

Select intnet (can be renamed, all virtual machines in the same LAN have the same name)

Advanced - control chip selection PCnet-FAST III

Advanced - hybrid mode rejected

Advanced - access line √
(virtual machine ip: for XP, ip can be automatically obtained, but for linux, ip and subnet mask must be manually configured, and each virtual machine ip must be in the same network segment when manually configured.)

ip style:

ip 169.254.147.9

Subnet mask 255.255.0.0

Default gateway none

Principle:

Each virtual machine USES VirtualBox's built-in DHCP server to obtain ip. The packets are transmitted without passing through the network where the host is located, so the security is high to prevent external packet capture

5. NAT mode + port mapping

Mapping a virtual machine port to a host port enables the host and external machines to access the services provided by the virtual machine

The command is as follows:

(in command line mode, 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


Related articles: