在上一章中,使用了Bridged(桥接)模式配置网络链接。
这一章中,我们使用Network Address Translation (NAT)配置网络链接。
http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1006480

Network Address Translation (NAT) networking

  • Used in environments where virtual machines do not provide services but still need to access a network.
  • Connects virtual machines to an external network, using the host machines IP address for external communication.
  • Connects virtual machines to the Internet through their host machines dial-up connection, Ethernet adapter or wireless Ethernet adapter.
  • Connects virtual machines to a non-Ethernet network, such as Token Ring or ATM.
  • Establishes a private LAN shared only by your host machine and any other virtual machines also using NAT networking.
  • Other host machines on the host LAN can communicate with the virtual machines, however external host machines cannot initiate communication with virtual machines unless NAT port forwarding is also in use. NAT port forwarding causes network traffic destined for a port on a host machine to be forwarded to a specific port on a virtual machine.
  • The default network adapter interface is vmnet8.

简单的说,就是利用网络适配器接口vmnet8,通过主机所在网络连接到Internet,主机所在局域网的其他主机无法直接连到虚拟机。利用UAT,可以把几台虚拟机构成一个局域网。

首先,我们在VM中配置Network Adapter,选择NAT。(具体见附件“Network Adapter NAT”)
然后,在Windows中启动VMware NAT Service。(net start "VMware NAT Service")
接着,在Windows中配置网络链接VMnet8的Internet协议,选择手动输入IP地址:
            比如IP地址输入192.168.66.4,子网掩码输入255.255.255.0。确定后可以在控制台中查得如下信息:
            Ethernet adapter VMware Network Adapter VMnet8:

                    Connection-specific DNS Suffix  . :
                    Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet8
                    Physical Address. . . . . . . . . : 00-50-56-C0-00-08
                    Dhcp Enabled. . . . . . . . . . . : No
                    IP Address. . . . . . . . . . . . : 192.168.66.4
                    Subnet Mask . . . . . . . . . . . : 255.255.255.0
                    Default Gateway . . . . . . . . . :
                    Primary WINS Server . . . . . . . : 192.168.75.2
            重点是留意这里的WINS Server。我们将会选择该地址作为Solaris的DNS以及网关地址。
最后,Solaris的网络配置如下(hostname为Solaris10u9Tianyu),配置完记得重启网络(svcadm disable network/physical, svcadm enable network/physical):
# cat /etc/hosts
#
# Internet host table
#
127.0.0.1       localhost
::1     localhost
192.168.75.88   Solaris10u9Tianyu       loghost
# cat /etc/resolv.conf
nameserver 192.168.75.2
nameserver 211.162.61.235
# cat /etc/netmasks
192.168.75.1 255.255.255.0
# cat /etc/defaultrouter
192.168.75.2
# cat /etc/nsswitch.conf | grep hosts
# "hosts:" and "services:" in this file are used only if the
hosts:      files  dns
# ping www.baidu.com
www.baidu.com is alive

尽管配置完了,但是你在主机中使用Putty连接到虚拟机,会发现"Network error: Connection timed ouot"。很奇怪的是在主机中ping虚拟机,可以通。
C:\>ping 192.168.75.88

Pinging 192.168.75.88 with 32 bytes of data:

Reply from 192.168.75.88: bytes=32 time<1ms TTL=255
Reply from 192.168.75.88: bytes=32 time<1ms TTL=255
Reply from 192.168.75.88: bytes=32 time<1ms TTL=255
Reply from 192.168.75.88: bytes=32 time<1ms TTL=255

Ping statistics for 192.168.75.88:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

于是,我们尝试在Windows中启动VMnetDHCP(net start VMnetDHCP)。然后把vmnet8的IP设置改为自动获取,确定后可以得到如下信息:
Ethernet adapter VMware Network Adapter VMnet8:

        Connection-specific DNS Suffix  . :
        Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for
VMnet8
        Physical Address. . . . . . . . . : 00-50-56-C0-00-08
        Dhcp Enabled. . . . . . . . . . . : Yes
        Autoconfiguration Enabled . . . . : Yes
        IP Address. . . . . . . . . . . . : 192.168.75.1
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . :
        DHCP Server . . . . . . . . . . . : 192.168.75.254
        Primary WINS Server . . . . . . . : 192.168.75.2
        Lease Obtained. . . . . . . . . . : 2011年4月17日 10:43:16
        Lease Expires . . . . . . . . . . : 2011年4月17日 11:13:16
然后,Solaris的网络配置不去改变,只是重启网络而已:
svcadm disable network/physical, svcadm enable network/physical

发现,在主机中使用Putty可以连接到虚拟机了。