admin管理员组

文章数量:1540694

2023年12月16日发(作者:)

VMware是很受欢迎的虚拟机,在我们平时的工作中需要经常用到,此文简单总结了平时使用的三种网络配置方式,具体的原理没有去深究。

虚拟机系统安装的是Linux系统。

首先,我们在本机上查看所有网络配置连接,使用命令:ipconfig

Java代码

1. Microsoft Windows XP [版本 5.1.2600]

2. (C) 版权所有 1985-2001 Microsoft Corp.

3.

4. C:Documents and Settingsuser>ipconfig

5.

6. Windows IP Configuration

7.

8.

9. Ethernet adapter VMware Network Adapter VMnet8:

10.

11. Connection-specific DNS Suffix . :

12. IP Address. . . . . . . . . . . . : 192.168.74.1

13. Subnet Mask . . . . . . . . . . . : 255.255.255.0

14. Default Gateway . . . . . . . . . :

15.

16. Ethernet adapter VMware Network Adapter VMnet1:

17.

18. Connection-specific DNS Suffix . :

19. IP Address. . . . . . . . . . . . : 192.168.2.1

20. Subnet Mask . . . . . . . . . . . : 255.255.255.0

21. Default Gateway . . . . . . . . . :

22.

23. Ethernet adapter 无线网络连接:

24.

25. Connection-specific DNS Suffix . :

26. IP Address. . . . . . . . . . . . : 192.168.1.209

27. Subnet Mask . . . . . . . . . . . : 255.255.255.0

28. Default Gateway . . . . . . . . . : 192.168.1.1

29.

30. Ethernet adapter 本地连接:

31.

32. Media State . . . . . . . . . . . : Media d

isconnected

33.

34. Ethernet adapter VirtualBox Host-Only Network:

35.

36. Connection-specific DNS Suffix . :

37. IP Address. . . . . . . . . . . . : 192.168.154.1

38. Subnet Mask . . . . . . . . . . . : 255.255.255.0

39. Default Gateway . . . . . . . . . :

40.

41. C:Documents and Settingsuser>

Microsoft Windows XP [版本 5.1.2600]

(C) 版权所有 1985-2001 Microsoft Corp.

C:Documents and Settingsuser>ipconfig

Windows IP Configuration

Ethernet adapter VMware Network Adapter VMnet8:

Connection-specific DNS Suffix . :

IP Address. . . . . . . . . . . . : 192.168.74.1

Subnet Mask . . . . . . . . . . . : 255.255.255.0

Default Gateway . . . . . . . . . :

Ethernet adapter VMware Network Adapter VMnet1:

Connection-specific DNS Suffix . :

IP Address. . . . . . . . . . . . : 192.168.2.1

Subnet Mask . . . . . . . . . . . : 255.255.255.0

Default Gateway . . . . . . . . . :

Ethernet adapter 无线网络连接:

Connection-specific DNS Suffix . :

IP Address. . . . . . . . . . . . : 192.168.1.209

Subnet Mask . . . . . . . . . . . : 255.255.255.0

Default Gateway . . . . . . . . . : 192.168.1.1

Ethernet adapter 本地连接:

Media State . . . . . . . . . . . : Media disconnected

Ethernet adapter VirtualBox Host-Only Network:

Connection-specific DNS Suffix . :

IP Address. . . . . . . . . . . . : 192.168.154.1

Subnet Mask . . . . . . . . . . . : 255.255.255.0

Default Gateway . . . . . . . . . :

C:Documents and Settingsuser>

上面内容中,我们可以看到本地连接及其它虚拟连接,其中VMware Network Adapter

VMnet8、VMware Network Adapter VMnet1和本地连接是我们在各种模式下要使用的不同连接网络配置。

本地连接:是本机用Bridge方式与虚拟机交互时使用的主机网卡;

VMware Network Adapter VMnet1:是本机用Host-Only方式与虚拟机交互时使用的虚拟网卡;

VMware Network Adapter VMnet8:是本机用NAT方式与虚拟机交互时使用的虚拟网卡;

接下来是试验结论:

1、Bridge模式:

Bridge模式使用的网卡是:本地连接,及物理网卡

设置方法:

a.在命令行使用ipconfig命令,获取本地连接的网络IP地址,如上为:172.16.2.41;

b.设置虚拟机的IP地址与本地连接的IP地址在同一网段,如172.16.2.241;

c.使用service network restart命令重启网络配置;

d.使用ping 命令检查网络是否畅通,如:ping 172.16.2.41。

2、Host-Only模式:

Host-Only模式使用的网卡是:VMware Network Adapter VMnet1

设置方法:

a.在命令行使用ipconfig命令,获取主机上VMware Network Adapter VMnet1的网络IP地址,如上为:192.168.2.1;

b.设置虚拟机的IP地址与VMware Network Adapter VMnet1的IP地址在同一网段,如192.168.2.241;

c.使用service network restart命令重启网络配置;

d.使用ping 命令检查网络是否畅通,如:ping 192.168.2.1。

3、NAT模式:

NAT模式使用的网卡是:VMware Network Adapter VMnet8

设置方法:

a.在命令行使用ipconfig命令,获取主机上VMware Network Adapter VMnet8的网络IP地址,如上为:192.168.74.1;

b.设置虚拟机的IP地址与VMware Network Adapter VMnet8的IP地址在同一网段,如192.168.74.241;

c.使用service network restart命令重启网络配置;

d.使用ping 命令检查网络是否畅通,如:ping 192.168.74.1。

理解VMware的3种网络模型

来源: ChinaUnix博客 日期: 2007.05.16 11:23 (共有条评论) 我要评论

st和 Host互联,其实这并不是一件困难的事情,只要能够理解 VMware的网

的虚拟机,来详细介绍一下 VMware的 3种网络结构

型之前,先说一下 VMware的几个虚拟设备:

用于虚拟桥接网络下的虚拟交换机;

用于虚拟 Host-Only网络下的虚拟交换机;

用于虚拟 NAT网络下的虚拟交换机;

pter VMnet1:这是 Host用于与 Host-Only虚拟网络进行通信的虚拟网卡;

pter VMnet8:这是 Host用于与 NAT虚拟网络进行通信的虚拟网卡;

的网卡在 VMnet0交换机上通过虚拟网桥进行桥接,这也就是说,我的物理网卡和我的 Guest的虚拟网卡(注:这个虚拟网卡不ware Network Adapter VMnet8)处于同等地位,此时的 Guest就好像我的 Host所在的一个网段上的另外一台机器。打个比如下:

关为 192.168.0.1,那么我的 Guest就应该和我的 Host处于同一个网段,它的配置可为:

方式,网关也为 192.168.0.1,这样的话,IP地址为 192.168.0.2的 Host和IP地址为

就可以互通了:

址一定要在 192.168.0网段没有被占用,而且我的网络管理员允许我来使用这个 IP地址。如果在 192.168.0网段,存在 DHCP服设置为 DHCP方式。

网络的定义(引用自 VMware GSX Server User’s Manual):

ects a virtual machine to a network using the host computer's Ethernet adapter.

up automatically if you select Use bridged networking in the New Virtual Machine Wizard or if you select the Typical

ost only if you enable the bridged networking option when you install GSX Server.

on an Ethernet network, bridged networking is often the easiest way to give your virtual machine access to that netwworking to connect to either a wired or a wireless network. On a Linux host, you can use bridged networking to conrking, your virtual machine needs to have its own identity on the network. Forexample, on a TCP/IP network, the

work administrator can tell you whether IP addresses are available for your virtual machine and what networking sem. Generally, your guest operating system may acquire an IP address and other network details automatically froddress and other details manually in the guest operating system.

rking, the virtual machine is a full participant in the network. It has access to other machines on the network and ck as if it were a physical computer on the network.

computer is set up to boot multiple operating systems and you run one or more of them in virtual machines, youunique network address.

operating systems often assign all systems the same address, since they assume only one operating system willating systems in a virtual machine, this assumption is no longer true.

selection in the New Virtual Machine Wizard and later decide you want to use bridged networking, you can make tVM > Settings). For details, see Changing the Networking Configuration.

Mnet8虚拟交换机, Host上的 VMware Network Adapter VMnet8虚拟网卡被连接到 VMnet8交换机上,来与 Guest进行通仅仅是用于和 VMnet8网段通信用的,它并不为 VMnet8网段提供路由功能,处于虚拟 NAT网络下的 Guest是使用虚拟的 NA,在 NAT网络下,我们甚至可使用 Port Forwarding功能,来把 Host的某一个 TCP或者 UDP端口映射到 Guest上!

ork Adapter VMnet8虚拟网卡的 IP地址配置如下:

不是由我来指定的,而是 VMware在安装的时候自动随机指定的一个 IP地址(注意,不要修改 VMware Network Adapter VMneuest无法通信)那么,我的 NAT网络的虚拟机的 IP地址也为 192.168.85.0这个网段,其 IP地址配置为:

是由 DHCP服务器分配的的, DHCP服务器的地址为 192.168.85.254,那为什么会有 DHCP服务器存在呢?这是因为 VMwa分配 IP地址,这个 DHCP服务器,你可以 ping通它,但是无法进行访问,因为实际上它就是一个系统服务而已,在开始—— >

卡和 Host上的 VMware Network Adapter VMnet8虚拟网卡拥有相同的网络 ID,这样的话,在 Guest中,ping通 Host就

AT方式的网络中, Guest的 Gateway都指向了 192.168.X.2,在本例中,X=85,也就是那个虚拟的 NAT服务器的地址,这但是却无法访问到这台虚拟机,因为这同样也是一个系统服务:

st就可以实现互访了,并且如果我的 Host此时已经连接到了 Internet,那么我的 Guest也就可以连上 Internet了。那么 Ho在这里扮演了一个什么角色呢?它仅仅是为 Host和 NAT虚拟网络提供了一个通信接口,所以,即便在 Host中 Disable掉这块再访问 VMnet8网段,也即是无法访问 Guest而已。

的定义(引用自 VMware GSX Server User’s Manual):

ine access to network resources using the host computer's IP address.

ation connection is set up automatically if you follow the Custom path in the New Virtual Machine Wizard and sele the Internet or other TCP/IP network using the host computer's dial-up networking or broadband connection andIP address on the external network, NAT is often the easiest way to give your virtual machine access to that netwonnect to a TCP/IP network using a Token Ring adapter on the host computer.

ual machine does not have its own IP address on the external network. Instead, a separate private network is set

s an address on that network from the VMware virtual DHCP server. The VMware NAT device passes network data and the external network. It identifies incoming data packets intended for each virtual machine and sends them tual machine can use many standard TCP/IP protocols to connect to other machines on the external network. For ex to transfer files and Telnet to log on to other computers. In the default configuration, computers on the externalns to the virtual machine. That means, for example, that the default configuration does not let you use the virtual

mputers on the external network.

selection in the New Virtual Machine Wizard and later decide you want to use NAT, you can make that change in theor details, see Changing the Networking Configuration.

cussion of NAT, see Understanding NAT.

t-Only网络被用来设计成一个与外界隔绝的(isolated)网络,其实 Host-Only网络和 NAT网络非常相似,唯一不同的地方就是务器为 VMnet1网络做路由,它当然就没有办法访问 Internet啦,可是如果此时我的 Host要和 Guest通信怎么办呢?当然就要网卡了。

的 VMware Network Adapter VMnet1虚拟网卡的配置,同样, VMware也为我自动随机分配好了它的 IP:

/photo/32519_]络设置成了 Host-Only的话,把它的 IP获取方式设置为 DHCP,它会到虚拟的 DHCP服务器上拿到 IP,这个 DHCP服务器仍然已),而且在下图中,可以看到,这个 DHCP服务器的 IP地址仍然是 192.168.X.254,这里 X=163,因为要和我的 VMnet1的网的 VMware Network Adapter VMnet1虚拟网卡的 IP使用同一个网络 ID:

络下, Guest的 Default Gateway被设置为 NULL,这是由于没有默认路由器为它到外部网络提供路由的缘故,也即是上边说到的dd命令加上某个地址做为它的路由器,它仍然不能访问 Internet(实际上也没有地址可加)。这样,我的 Guest虽然没有办法访正是因为我的 Host上的 VMware Network Adapter VMnet1虚拟网卡起到了作用,它负责和 VMnet1网络相连,为我访问 H了在 Host-Only网络中的 Guest 与我的 Host的通信情况:

网络设置为没有 Default Gateway的方式,这是 VMware的设计使然,它就是让我们建立一个与外界隔离(isolated)的网络时y网络的定义(引用自 VMware GSX Server User’s Manual):

eates a network that is completely contained within the host computer.

t up automatically if you select Use Host-Only Networking in the New Virtual Machine Wizard. On Linux hosts, this

nly networking option when you installed GSX Server.

ovides a network connection between the virtual machine and the host computer, using a virtual Ethernet adapter

pproach can be useful if you need to set up an isolated virtual network.

orking, your virtual machine and the host virtual adapter are connected to a private TCP/IP network. Addresses on tver.

selection in the New Virtual Machine Wizard and later decide you want to use host-only networking, you can make

VM > Settings). For details, see Changing the Networking Configuration.

Sharing If you install the proper routing or proxy software on your host computer, you can establish a connectionphysical network adapter on the host computer. This allows you, for example, to connect the virtual machine to a

Windows Server 2003 host computer, you can use host-only networking in combination with the Internet connectioal machine to use the host's dial-up networking adapter or other connection to the Internet. See your Windows docnection sharing.

可以在 Host上来为 VMware Network Adapter VMnet1虚拟网卡来做路由。比如,我可以用 Windows 2000的 RRAS来做,上网了,它们只需要使用 route add命令把自己的 Default Gateway指向 Host上的 VMware Network Adapter VMnet1虚拟际做一下看看)。

,就应该可以理解了。可以看到,如果想要 Guest上网,在 3种网络模型中,最为简单的方式就是 NAT,因为它不需要任何的网,要做的仅仅就是把它的网络设置为 NAT方式即可。至于 Bridged模式,则需要额外的 IP地址,这有可能会实现不了,因为并要设置 RRAS,没有几个人会愿意为了让虚拟机上网而换 OS的,所以就用 NAT最好了。在这里要强调的一点是,如果设置了 Host-而不要用 Windows XP或者 2000的 ICS,因为

改为 192.168.0.1。你在安装虚拟机的时候,VMware不会正好给你的 VMware Network Adapter VMnet1虚拟网卡分配为 1work Adapter VMnet1虚拟网卡和 VMnet1网段的网络 ID不一致,自然,你的 Guest就没有办法和 Host通信了!

情况:比如 VMware为我分配的网络 ID在将来会被我用到,或者嫌 VMware为你分配的网络不好(比如它给你分了个 192.16单,选择“Virtual Network Settings ...”

rk Mapping”中,VMnet1所在的虚拟网络,单击后边的按钮,选择 “Subnet”菜单,即可以调整你的网络 ID。

,那么 VMnet8当然也可以用这样的方式来调整。 .

ware Network Adapter VMnet1和 VMware Network Adapter VMnet8也需要调整到相应的网络 ID,不然 Host和 Guest时候,总是喜欢直接修改 VMware Network Adapter VMnet1和 VMware Network Adapter VMnet8这两块虚拟网卡的 IP地址和上网,实际上在看过这篇文章之后,应该明白,修改这两块虚拟网卡,对于实现网络通信,是多么的没有帮助!

本文标签: 网络虚拟网卡使用命令