开发人员常常需要利用虚拟机在本机搭建虚拟局域网环境。下面分别介绍单局域网和双局域网的搭建方法。
◆ 单局域网的搭建
注:在此网络环境中,需运行2个VM。本机的角色为外网机器。
网络结构图:
~~~~~~~~~~~
+------本机-----+
| 192.168.1.100 |
+-------+-------+
|
------------+--------------------------------------
| (LAN)
|
+---局域网网关(VM)--+
| NIC1: 192.168.1.1 | +-内网机器(VM)-+
| NIC2: 192.168.0.1 +----------+ 192.168.0.2 |
+-------------------+ +--------------+
设置步骤:
~~~~~~~~~
1. Virtual Network Settings:
VMnet1: VMware Network Adapter VMnet1
Subnet: IP Address: 192.168.0.0
Subnet Mask: 255.255.255.0
禁用 DHCP 服务。
2. Team Settings:
Virtual Machine Adapter LAN1 Bridged NAT Host-only
--------------- ------- ---- ------- --- ---------
VM1 (网关) Ethernet √
Ethernet2 √
VM2 (内网机器) Ethernet √
3. VM1 (网关) 网络设置:
NIC1:
IP地址: 192.168.1.1
子网掩码: 255.255.255.0
打开 Internet 连接共享。
NIC2 (Lan):
IP地址: 192.168.0.1
子网掩码: 255.255.255.0
4. VM2 (内网机器) 网络设置:
NIC1:
IP地址: 192.168.0.2
子网掩码: 255.255.255.0
默认网关: 192.168.0.1
5. 本机设置:
VMware Network Adapter VMnet1:
IP地址: 192.168.1.100
子网掩码: 255.255.255.0
6. 网络测试:
在 VM2 中:
C:\> ping 192.168.1.100
若能 ping 通,则说明成功。
◆ 双局域网的搭建
注:在此网络环境中,需运行3个VM。本机的角色为Lan1的内网机器。
网络结构图:
~~~~~~~~~~~
+---Lan1 网关(VM)---+ +-----本机-----+
| NIC1: 192.168.0.1 +----------+ 192.168.0.2 |
| NIC2: 192.168.1.1 | +--------------+
+---------+---------+
|
| (Lan 1)
------------+--------------------------------------
| (Lan 2)
|
+---Lan2 网关(VM)---+
| NIC1: 192.168.1.2 | +-内网机器(VM)-+
| NIC2: 192.168.0.1 +----------+ 192.168.0.2 |
+-------------------+ +--------------+
设置步骤:
~~~~~~~~~
1. Virtual Network Settings:
VMnet1: VMware Network Adapter VMnet1
Subnet: IP Address: 192.168.0.0
Subnet Mask: 255.255.255.0
禁用 DHCP 服务。
2. Team Settings:
Virtual Machine Adapter WAN LAN Bridged NAT Host-only
--------------- ------- --- --- ------- --- ---------
VM (Lan1 网关) Ethernet √
Ethernet2 √
VM (Lan2 网关) Ethernet √
Ethernet2 √
VM (Lan2 内网机器) Ethernet √
3. VM (Lan1 网关) 网络设置:
NIC1 (Lan):
IP地址: 192.168.0.1
子网掩码: 255.255.255.0
NIC2:
IP地址: 192.168.1.1
子网掩码: 255.255.255.0
打开 Internet 连接共享。
4. VM (Lan2 网关) 网络设置:
NIC1:
IP地址: 192.168.1.2
子网掩码: 255.255.255.0
打开 Internet 连接共享。
NIC2 (Lan):
IP地址: 192.168.0.1
子网掩码: 255.255.255.0
5. VM (Lan2 内网机器) 网络设置:
NIC1:
IP地址: 192.168.0.2
子网掩码: 255.255.255.0
默认网关: 192.168.0.1
6. 本机设置:
VMware Network Adapter VMnet1:
IP地址: 192.168.0.2
子网掩码: 255.255.255.0
默认网关: 192.168.0.1
7. 网络测试:
在本机:
C:\> ping 192.168.1.2
若能 ping 通,则说明成功。