VirtualBox build a virtual machine from the master 2

 

 

 

 

 

 

 

 

 

 

 

Environmental requirements

Recently set up a test environment using VirtualBox, as the company provides all the machines are not using a fixed IP, it must be acquired automatically by DHCP.

In order not to affect the company's consolidation of the network environment, only the experimental network environment restrictions on the use of internal IP. Thus, this experiment environment must meet the following requirements (note that this is a relationship AND three demands must be met at the same time):
Requirement 1: can be accessed from the host through a static IP to each virtual machine can access the host computer from a virtual machine ( the host also has a fixed static IP)
Requirement 2: composition of a network consisting of a static IP between virtual machines, between a virtual machine and can communicate with each other
requirements 3: from the host, the virtual machine can access the internet
like this:

The basic idea

In order to meet the three requirements above, I am going to add three NICs inside the virtual machine is done, ideas are as follows:
eth0: 1 card, only the host (Host-Only) adapter connections, to meet requirement 1, namely: from the host access to each of the virtual machine by a static the IP, can access to the host from the virtual machine (the host has a fixed static the IP)
eth1: card 2, using the internal network connection, to meet requirement 2, namely: between virtual machines form a network consisting of a static IP, and between virtual machines can access each other
eth2: 3 card, use network address Translation (NAT) connection, you need to complete 3, namely: the host can access the internet from a virtual machine
says so many, in fact, worse one, so in the end between the host and the virtual machine is how connected it?

Careful people may find that after we installed VirtualBox, the host system which will be more of a connection, VirtualBox Host-Only Network, this is VirtualBox automatically generated a connection; and the other local connection is to connect the actual network card :

FIG two connections, and a virtual machine inside the three cards with each other to form a network structure below:

 

Configuring a static IP network hosts

打开 Orcale VM VirtualBox管理器,从菜单中选择 管理 – 全局设定;在弹出的窗口中选择 网络,然后再选择 仅主机(Host-Only)网络(H) 标签页,双击 VirtualBox Host-Only Ethernet Adapter, 修改里面的IP地址,为了尊重传统,我选择192.168.1.1,如下图所示;

接着,关闭DHCP服务器,如下图所示:

也就是说,现在主机由一个静态IP:192.168.1.1。之后,虚拟机就可以通过这个IP地址来访问主机了。

上述设定完成后,查看主机的地址,可以看到如下的信息;

配置虚拟机的网卡

加入第一块网卡 eth0,将 eth0 配置成如下图的方式:


接着加入第二块网卡 eth1,将 eth1 配置成如下图的方式:

注意,虚拟机之间的内网名字可以随便起,这里叫做 neta。如果在配置在第二个虚拟机的时候,也要记得选择 netca 这个内网名字,这样虚拟机之间才可以互相通信。

最后,加入第三块网卡 eth2,配置如下:

 

保存,启动虚拟机,安装系统。

在虚拟机内部配置网卡

在这里我使用了Oracle Linux(其实和CentOS,RHEL是一毛一样的)。在配置IP的时候,用命令行来配置各个网卡的IP信息,如果你喜欢,也可以使用GUI(NetworkManager)。

首先 eth0,这里要与主机保持的一个网段(192.168.1.),把 eth0 的IP地址配置为 192.168.1.2:

其次,配置 eth1,要注意内网我们选择 192.168.0. 这个网段,eth1 的IP地址配置为 192.168.0.2:

再次,配置 eth2, 因为是NAT地址转换的,这块网卡使用DHCP来自动获取IP,具体如下:

最后,重新启动一下网络服务:
# service network restart
查看一下我们配置后的结果:

也就是说,现在这台虚拟机有三个IP:
192.168.1.2: 和主机通信使用
192.168.0.2: 和其他的虚拟机通信使用
10.0.4.15: 是自动获取的,通过VirtualBox的地址转换功能,用来访问外网internet
如果再新建一台虚拟机,还是需要参考上面的步骤,为每个虚拟机都设置三块网卡。

对需求1的验证
通过主机来 ping 虚拟机,结果如图,成功!


需求2的验证
虚拟机之间互 ping,结果如图,成功!

需求3的验证
从虚拟机直接上外网,如图,成功!(注意:请确认你的主机和虚拟机都使用了相同的代理服务器设置)

 

Guess you like

Origin www.cnblogs.com/htkj/p/10932383.html