VirtualBox Virtual Machine network settings (four methods)

Source: Internet
Author: User
Tags custom name ssh server

Source: douban network engineering team
 
VirtualBox provides four network access modes:
1. NAT Network Address Translation mode (NAT, Network Address Translation)
2. Bridged Adapter Bridging Mode
3. Internal network mode
4. Host-only Adapter Host Mode
 
First NAT Mode
Explanation:
The NAT mode is the simplest way to access the Internet through virtual machines. You can understand that all data accessed by Vhost is provided by the host, and vhost does not actually exist in the network, the existence of the Vhost cannot be viewed or accessed by any host on the host or network.
Relationship between virtual machines and hosts:
Only one-way access is allowed. virtual machines can access the host through the network, and the host cannot access the virtual machine through the network.
Relationship between virtual machines and other hosts in the network:
Only one-way access is allowed. virtual machines can access other hosts in the network, while other hosts cannot access virtual machines through the network.
Relationship between virtual machines:
Mutual access is not allowed. virtual machines and virtual machines are completely independent of each other and cannot access each other through the network.
IP: 10.0.2.15
Gateway: 10.0.2.2
DNS: 10.0.2.3
Multiple NICs of a virtual machine can be configured with NAT. The first Nic is connected to the private network 10.0.2.0, and the second Nic is connected to the private network 10.0.3.0. The Default Client ip Address is 10.0.2.15, the Gateway is 10.0.2.2, And the DNS is 10.0.2.3.
NAT solution advantages and disadvantages:
When a laptop has a network cable inserted: the virtual machine can access the host, and the virtual machine can access the internet. After port ing (as described in the end), the host can access services (such as databases) on the virtual machine ).
When no network cable is inserted in the notebook: the "local connection" of the host has a Red Cross, the virtual machine can access the host, and the virtual machine cannot access the Internet. After port ing, the host can access services (such as databases) on virtual machines ).
 
The second Bridged Adapter Mode
Explanation:
The bridge mode is my favorite mode, and the simulation degree is also quite perfect. As you can understand, it sets up a bridge through the host Nic and connects it directly to the network. Therefore, 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.
Relationship between virtual machines and hosts:
Mutual access is allowed because the virtual machine has an independent IP address in the real network segment. The host and the virtual machine are in the same network segment and can access each other through their respective IP addresses.
Other VM relationships in the network:
Mutual access is allowed. Because the virtual machine has an independent IP address in the real network segment, the virtual machine and other hosts on the network are in the same network segment and can access each other through their respective IP addresses.
Relationship between virtual machines and virtual machines:
They can access each other for the same reason.
IP Address: It is generally allocated by DHCP. It is in the same network segment as the "local connection" IP address of the host. The VM can communicate with the host.
When a laptop has a network cable inserted: (if there is a DHCP server in the Network) the host and the virtual machine obtain an IP address through DHCP. The two IP addresses are in the same network segment. The host and virtual machine can be pinged, and the virtual machine can be connected to the Internet.
When no network cable is inserted in the notebook: the host cannot communicate with the virtual machine. If the host's "Local Connection" has a Red Cross, you cannot manually specify an IP address. The virtual machine cannot obtain an IP address through DHCP. After the IP address is manually specified, it cannot communicate with the host because the host has no IP address.
In this case, the VirtualBox Host-Only Network adapter of the Host has an ip address, 192.168.56.1. Even if the IP address 192.168.56. * is manually specified for the VM, the host cannot be pinged.
 
Third Internal Mode
Explanation:
Intranet mode, as its name implies, is the internal network mode. virtual machines are completely disconnected from the Internet, and only the internal network mode between virtual machines is implemented.
Relationship between virtual machines and hosts:
They cannot access each other. They do not belong to the same network and cannot access each other.
Relationships between virtual machines and other hosts in the network:
Mutual access is not allowed for the same reason.
Relationship between virtual machines and virtual machines:
Mutual access is allowed, provided that the two virtual machines set the same network name when setting the network. In the preceding configuration chart, the name is intnet.
IP: the DHCP server of VirtualBox will assign an IP address to it. Generally, 192.168.56.101 is obtained. Because the IP address ranges from 101, you can also manually specify 192.168.56 .*.
When a laptop has a Network cable inserted: the VM can communicate with the VirtualBox Host-Only Network adapter of the Host.
This solution is not affected by the host's local connection (NIC.
 
Fourth Host-only Adapter Mode
Explanation:
Host mode. This is a complex mode that requires a solid basic network knowledge. It can be said that the functions implemented in the previous modes can be achieved through virtual machine and nic settings in this mode.
We can understand that the Vbox model a dedicated Nic for the virtual machine in the host. All virtual machines are connected to the NIC. We can set this Nic to achieve Internet access and many other functions, such as NIC sharing and nic bridging ).
Relationship between virtual machines and hosts
Mutual access is not allowed by default. Both parties do not belong to the same IP segment. The default IP segment of the host-only NIC is 192.168.56.X, And the subnet mask is 255.255.255.0. The virtual machines allocated to the backend are also located in This CIDR block. Through Nic sharing and nic bridging, virtual machines can access each other on the host.
Relationship between virtual machines and network hosts
Mutual access is not allowed by default. The reason is the same as above. Mutual access can be achieved through settings.
Relationship between virtual machines and virtual machines
Mutual access is allowed by default, and both are in the same network segment.
The VM accesses the Host using the VirtualBox Host-Only Network Nic IP address 192.168.56.1 of the Host, regardless of whether the Host "Local Connection" has a Red Cross, always pass.
When the host accesses the VM, it uses the IP address 192.168.56.101 of network interface card 3 of the VM, regardless of whether the host is "locally connected" or not, it will always be connected.
When a virtual machine accesses the internet, it uses its own network adapter 2. In this case, the host must be able to access the Internet through a "Local Connection" Wired Network (wireless network adapter is unavailable)
 
By understanding the above several network modes, we can use them flexibly to simulate the establishment of any network environment we want.
For example, I want to simulate a host to monitor the network environment of a local area network.
First, I started two virtual machines, vhost1 and vhost2. Of course, if the hardware permits, I can also add vhost3, vhost4...
All vhosts are set to internat Intranet mode. The network name is intnal and the gateway is 192.168.56.100, which means accessing the Internet through the 192.168.56.100 Nic. One vhost1 is set to a dual-nic, one is the Intranet mode (192.168.56.100), and the other is the bridge mode (192.168.1.101 ). Set two NICs to share the Internet
There is a LAN between virtual machines. One of them is connected to the Internet through vhost1, and all the virtual machines in the LAN are connected to the Internet through vhost1. In this way, vhost1 can monitor the Internet access of the entire virtual machine LAN.
 
NAT set port http://www.bkjia.com/ OS /201202/119950.html ing
You can set a virtual machine service (such as a WEB service) by using the command line tool VboxManage proxy. You need to know which port is used by the virtual machine service, and then decide which port is used on the host (usually but not always want to make the virtual machine and the host use the same port ). A port is required to provide a service on the host. You can use any port on the host that is not prepared to provide the service. How to set up a new NAT instance and connect to an ssh server on a VM requires the following three commands:
VBoxManage setextradata 'linux Guest ''' VBoxInternal/Devices/pcnet/0/LUN #0/Config/guestssh/Protocol 'tcp
VBoxManage setextradata 'linux guist' 'vboxinternal/Devices/pcnet/0/LUN #0/Config/guestssh/GuestPort '22
VBoxManage setextradata 'linux guist' 'vboxinternal/Devices/pcnet/0/LUN #0/Config/guestssh/hostport' 2222
Note: VboxManage is a command line program. Check your VirtualBox installation directory. 'linux Guest 'is the virtual host name. Guestssh is a custom name. You can set it as needed. Use the preceding three commands to forward port 22 of the VM to port 2222 of the host.
For example, I installed the apache2 server on the Virtual Machine debian and used port 80 to map it to port 80 of the host. Use the following command.
'C: \ Program Files \ innotek VirtualBox \ VBoxManage.exe 'setextradat' debian ''VBoxInternal/Devices/pcnet/0/LUN #0/Config/huzhangsheng/Protocol 'tcp
'C: \ Program Files \ innotek VirtualBox \ VBoxManage.exe 'setextradat' debian ''VBoxInternal/Devices/pcnet/0/LUN #0/Config/huzhangsheng/GuestPort '80
'C: \ Program Files \ innotek VirtualBox \ VBoxManage.exe 'setextradat' debian ''VBoxInternal/Devices/pcnet/0/LUN #0/Config/huzhangsheng/hostport' 80
Note: To make the settings take effect, turn off VirtualBox and run the virtual machine. I have installed VirtualBox on winxp and debian 4.02r on the virtual machine. The virtual machine name is debian, apache2 php5 mysql-server is installed, and http: // localhost is browsed with IE on the host, which is successfully forwarded to The apache2 web server of debian virtual machine.
 
Source: http://www.bkjia.com/ OS /201202/119951.html

I personally feel that using port ing is not as easy as directly bridging. Now, in most cases, it is okay to connect to the network, port ING also requires additional services on both the host and virtual machines.
 
The "network" configuration page has four solutions:
 
1: Network Address Translation)
 
2: Birdged Network bridging
 
3: Internal Network (between virtual machines)
 
4: Host-Only communicates with the Host (probably)
 
After VirtualBox2.2 is installed, the Host has an "VirtualBox Host-Only Network" Local Nic.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.