Virtualbox Virtual Machine network settings (four methods)

Source: Internet
Author: User
Tags custom name ssh server

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.

Configure port ing in Nat

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.

Virtualbox Virtual Machine network settings (four methods)

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.