How to set up the network of the virtual box virtual machine

Use the virtual machine intermittently, and sometimes some settings are easy to forget, such as setting the network.

The operation steps are as follows, if you have any questions, you can send me a private message or private message on Weibo.

  • Open the vitual box and find the settings

  • Click Settings to find the network. There are generally four ways to set the network of the virtual machine. We generally choose the NAT method. If you are interested in these four methods, you can read the attached text.

  • Click Advanced Settings to expand, configure as shown below


In this way, the virtual machine can access the Internet normally, as shown below




Attachment:

v irtualBox provides four network access modes, they are:

1. NAT Network Address Translation (NAT, Network Address Translation)

2. Bridged Adapter bridge mode

3. Internal internal network mode

4. Host-only Adapter host mode

 

The first NAT mode

explain:

NAT mode is the easiest way to implement virtual machines to access the Internet. You can understand it like this: All data that Vhost accesses the network is provided by the host, vhost does not really exist in the network, and neither the host nor any machine in the network can view it. and access to the presence of Vhost.

Virtual machine and host relationship:

Only one-way access is allowed. The virtual machine can access the host through the network, but the host cannot access the virtual machine through the network.

The relationship of the virtual machine to other hosts in the network:

Only one-way access is allowed. The virtual machine can access other hosts on the network, and other hosts cannot access the virtual machine through the network.

The relationship between virtual machines and virtual machines:

They cannot access each other. The virtual machine and the virtual machine are completely independent of each other, and they cannot access each other through the network.

IP:10.0.2.15

Gateway: 10.0.2.2

DNS:10.0.2.3

Multiple NICs in a virtual machine can be configured to use NAT, with the first NIC connected to the private network 10.0.2.0, the second NIC connected to the private network 10.0.3.0, and so on. The default client ip (IPAddress) is 10.0.2.15, the gateway (Gateway) is 10.0.2.2, and the domain name server (DNS) is 10.0.2.3. You can manually refer to this to modify.

Advantages and disadvantages of NAT scheme:

When the laptop is plugged into the network cable: the virtual machine can access the host, the virtual machine can access the Internet, and after port mapping is done (instructions at the end), the host can access services (such as databases) on the virtual machine.

When the laptop is not plugged into the network cable: the "local connection" of the host has a red cross, the virtual machine can access the host, but the virtual machine cannot access the Internet. After port mapping, the host can access the services (such as databases) on the virtual machine.

 

The second Bridged Adapter mode

explain:

Bridge mode is one of my favorite modes to use, and at the same time, the analog is quite perfect. You can understand it this way, it is directly connected to the network by setting up a bridge through the host network card. Thus, it enables virtual machines to be assigned to separate IPs on a network, with all network functions exactly as real machines on the network.

Virtual machine and host relationship:

They can access each other because the virtual machine has an independent IP 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 IPs.

The relationship between the virtual machine and other hosts in the network:

They can access each other. Also, because the virtual machine has an independent IP in the real network segment, the virtual machine and all other hosts on the network are in the same network segment and can access each other through their respective IPs.

Virtual machine to virtual machine relationship:

can access each other for the same reasons as above.

IP:一般是DHCP分配的,与主机的“本地连接”的IP 是同一网段的。虚拟机就能与主机互相通信。

笔记本已插网线时:(若网络中有DHCP服务器)主机与虚拟机会通过DHCP分别得到一个IP,这两个IP在同一网段。 主机与虚拟机可以ping通,虚拟机可以上互联网。

笔记本没插网线时:主机与虚拟机不能通信。主机的“本地连接”有红叉,就不能手工指定IP。虚拟机也不能通过DHCP得到IP地址,手工指定IP后,也无法与主机通信,因为主机无IP。

这时主机的VirtualBox Host-Only Network 网卡是有ip的,192.168.56.1。虚拟机就算手工指定了IP192.168.56.*,也ping不能主机。

 

第三种 Internal模式

解释:

内网模式,顾名思义就是内部网络模式,虚拟机与外网完全断开,只实现虚拟机于虚拟机之间的内部网络模式。

虚拟机与主机关系:

不能相互访问,彼此不属于同一个网络,无法相互访问。

虚拟机与网络中其他主机关系:

不能相互访问,理由同上。

虚拟机与虚拟机关系:

可以相互访问,前提是在设置网络时,两台虚拟机设置同一网络名称。如上配置图中,名称为intnet。

IP:VirtualBox的DHCP服务器会为它分配IP,一般得到的是192.168.56.101,因为是从101起分的,也可手工指定192.168.56.*。

笔记本已插网线时:虚拟机可以与主机的VirtualBox Host-Only Network 网卡通信

这种方案不受主机本地连接(网卡)是否有红叉的影响。

 

第四种 Host-only Adapter模式

解释:

主机模式,这是一种比较复杂的模式,需要有比较扎实的网络基础知识才能玩转。可以说前面几种模式所实现的功能,在这种模式下,通过虚拟机及网卡的设置都可以被实现。

我们可以理解为Vbox在主机中模拟出一张专供虚拟机使用的网卡,所有虚拟机都是连接到该网卡上的,我们可以通过设置这张网卡来实现上网及其他很多功能,比如(网卡共享、网卡桥接等)。

虚拟机与主机关系

默认不能相互访问,双方不属于同一IP段,host-only网卡默认IP段为192.168.56.X子网掩码为255.255.255.0,后面的虚拟机被分配到的也都是这个网段。通过网卡共享、网卡桥接等,可以实现虚拟机于主机相互访问。

虚拟机与网络主机关系

默认不能相互访问,原因同上,通过设置,可以实现相互访问。

虚拟机与虚拟机关系

默认可以相互访问,都是同处于一个网段。

虚拟机访问主机 用的是主机的VirtualBox Host-Only Network网卡的IP:192.168.56.1,不管主机“本地连接”有无红叉,永远通。

主机访问虚拟机,用是的虚拟机的网卡3的IP: 192.168.56.101 ,不管主机“本地连接”有无红叉,永远通。

虚拟机访问互联网,用的是自己的网卡2, 这时主机要能通过“本地连接”有线上网,(无线网卡不行)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326327485&siteId=291194637