Virtualbox Virtual Machine network settings (four methods)

Source: Internet
Author: User
Tags custom name ssh server
Virtualbox provides four network access modes:
1. Nat network address translation mode (NAT, Network Address Translation)
2. bridged adapter Bridging Mode
3. Internal internal network mode
4. Host-only adapter Host Mode

the first Nat mode
explanation:
the NAT mode is the simplest way to Implement Virtual Machine Internet access. You can understand it as follows: all data of the vhost accessing the network is provided by the host, and the vhost does not exist in the network. The host and any machine on the network cannot view and access the existence of the vhost.
relationship between the VM and the Host:
only one-way access is allowed. The VM can access the host over the network, and the host cannot access the VM over the network.
relationships between virtual machines and other hosts in the Network:
only one-way access is allowed. virtual machines can access other hosts in the network, and other hosts cannot access virtual machines through the network.
relationship between virtual machines:
the 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 to use NAT, the first Nic is connected to the private network 10.0.2.0, the second Nic is connected to the private network 10.0.3.0, and so on. 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.
advantages and disadvantages of the NAT solution:
when a network cable is inserted in a notebook, the virtual machine can access the host, and the virtual machine can access the internet. After port ing is completed (this is finally described ), the host can access services (such as databases) on virtual machines ).
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 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, and the host and virtual machine are in the same network segment, each Other 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 is in the same network segment as all other hosts on the network and can access each other through their respective IP addresses.
relationship between virtual machines:
mutual access is allowed for the same reason.
IP Address: generally assigned 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 the name suggests, is internal network mode. The virtual machine is completely disconnected from the Internet, only the internal network mode between virtual machines is implemented.
relationship between virtual machines and hosts:
mutual access is not allowed. virtual machines and hosts are not in the same network and cannot be accessed.
relationship between virtual machines and other hosts in the Network:
mutual access is not allowed for the same reason.
relationship between virtual machines:
mutual access is allowed, provided that the two virtual machines have the same network name when setting the network. In the preceding configuration chart, the name is intnet.
IP Address: the DHCP server of virtualbox will assign an IP address to it. Generally, 192.168.56.101 is obtained. Because the score starts 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, which is a complex mode. You must have a solid basic network knowledge before you can use it. 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 vbox is used to create a dedicated Nic in the host. All VMS are connected to this Nic, we can set this Nic to achieve Internet access and many other functions, such as NIC sharing and nic bridging ).
relationship between the VM and the host
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, this CIDR block is also assigned to virtual machines. 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
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 is connected locally or not.
when the host accesses the VM, it uses the IP address 192.168.56.101 of network adapter 3 of the VM, regardless of whether the host "Local Connection" has a red cross.
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" (wireless network adapter is not available)

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
Http: // huzhangsheng. Blog.163.com/blog/st Atic/347877842008028 01435931/
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 , Please query 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.cnblogs.cOM/coltiam/archive/2010/03/26/1696939 .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.

--------------------------------------------------------------------

My network environment:

Host:

System: XP

"Local Connection" IP Address: because it is a notebook, it is often used to change the working network environment, which is allocated through DHCP. Sometimes there is no network, "Local Connection" has a Red Cross (it affects the communication between the host and the virtual machine ).

"Virtualbox host-only network nic" IP Address: 192.168.56.1, because the DHCP server IP address of virtualbox is 192.168.56.100, it must be in the same network segment.

Virtual Machine: to communicate with the host, to access the Internet (no need to be accessed by the Internet ).

System: win2003

Nic 1, Nic 2, and nic 3

----------------------------------------------------------------------

--------------------------- Nic configuration --------------------------------------------

Nic 1: NAT solution

IP: 10.0.2.15

Gateway: 10.0.2.2

DNS: 10.0.2.3

Why is this configuration? The help of virtualbox contains the following description (English to Chinese ):

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 ).

Nic 2: birdged Network Solution

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.

Nic 3: Host-only solution

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.

When no network cable is inserted in the notebook: 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.

------------------------------------------------------------------

In the above three solutions, you can right-click the icons of the two small TVs at the bottom of the Virtual Machine window to quickly switch between them. Meet various network environments.

I did not try the internal network solution either.

Summary of the above three solutions

Enable the following two schemes:

Nic 2: birdged Network Solution

Nic 3: Host-only solution

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)

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.