按主机名寻址 VMWare Fusion Linux 来宾?

amr*_*rox 11 linux vmware-fusion ubuntu-9.04 hostname macos

我在 VMWare Fusion 3.0.0 中设置了一个 Ubuntu Server 9.04 映像,使用来宾网络连接的 NAT 选项。从 Mac 主机,我可以使用它的 IP 地址很好地 ssh 到 linux 来宾,但为了方便起见,我希望能够通过主机名来引用它。IE:

mac-host:~ ssh user@linux-guest.local
Run Code Online (Sandbox Code Playgroud)

几年前我使用 Parallels 进行了类似的设置,但我不记得它是如何设置的。它可能“刚刚起作用”。

关于如何使这项工作的任何建议?

Sha*_*nce 14

编辑我发布的第一个版本的说明导致与 VMware 在 vmnet8 上放置的名称服务器和网关发生冲突。这个版本修正了这个问题。

软件版本:

  • MAC OS X 版本 10.6.3
  • VMware Fusion 3.1.0 版 (261058)
  • Ubuntu 10.04 LTS

我做了什么:

  • 在创建 VM 期间,将网络设置为 NAT。

  • 在 Linux 客户机上:运行 ifconfig 以获取正在使用的硬件地址HWaddr、广播地址Bcast、IPv4 互联网地址inet addr和掩码Mask

    UbuntuGuest$ifconfig
    eth0      Link encap:Ethernet  HWaddr 00:0c:29:53:bf:e5  
              inet addr:192.168.213.129  Bcast:192.168.213.255  Mask:255.255.255.0
                     <snip>
    
    Run Code Online (Sandbox Code Playgroud)
  • 在 Linux 客户机上:查找名称服务器信息

    UbuntuGuest$cat /etc/resolv.conf
    nameserver 192.168.213.2
    domain localdomain
    search localdomain
    
    Run Code Online (Sandbox Code Playgroud)
  • 在 Linux 客户机上:查找网关地址:(在以 0.0.0.0 作为目标的行的网关列中列出。)

    UbuntuGuest$route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    192.168.213.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0
    0.0.0.0         192.168.213.2   0.0.0.0         UG    100    0        0 eth0
    
    Run Code Online (Sandbox Code Playgroud)
  • 在 OS X 主机上:编辑(NAT 虚拟交换机)的dhcpd.conf文件vmnet8以将静态 IP 地址分配给 Linux 客户机。(在第四行使用您选择的编辑器)

    OSXHost$cd /Library/Application\ Support/VMware\ Fusion/vmnet8/
    OSXHost$sudo chmod u+w dhcpd.conf
    OSXHost$sudo cp dhcpd.conf dhcpd.conf.bak.20100619
    OSXHost$sudo emacs dhcpd.conf
    
    Run Code Online (Sandbox Code Playgroud)
  • 在 OS X 主机上:该文件将开始看起来像:

    # Configuration file for ISC 2.0 vmnet-dhcpd operating on vmnet8.
    #
    # This file was automatically generated by the VMware configuration program.
    # See Instructions below if you want to modify it.
    #
    # We set domain-name-servers to make some DHCP clients happy
    # (dhclient as configured in SuSE, TurboLinux, etc.).
    # We also supply a domain name to make pump (Red Hat 6.x) happy.
    #
    
    
    ###### VMNET DHCP Configuration. Start of "DO NOT MODIFY SECTION" #####
    # Modification Instructions: This section of the configuration file contains
    # information generated by the configuration program. Do not modify this
    # section.
    # You are free to modify everything else. Also, this section must start
    # on a new line
    # This file will get backed up with a different name in the same directory
    # if this section is edited and you try to configure DHCP again.
    
    # Written at: 12/26/2009 10:35:10
    allow unknown-clients;
    default-lease-time 1800;                # default is 30 minutes
    max-lease-time 7200;                    # default is 2 hours
    
    subnet 192.168.213.0 netmask 255.255.255.0 {
          range 192.168.213.128 192.168.213.254;
          option broadcast-address 192.168.213.255;
          option domain-name-servers 192.168.213.2;
          option domain-name localdomain;
          default-lease-time 1800;         # default is 30 minutes
          max-lease-time 7200;             # default is 2 hours
      option routers 192.168.213.2;
    }
    host vmnet8 {
        hardware ethernet 00:50:56:C0:00:08;
        fixed-address 192.168.213.1;
        option domain-name-servers 0.0.0.0;
        option domain-name "";
        option routers 0.0.0.0;
    }
    ####### VMNET DHCP Configuration. End of "DO NOT MODIFY SECTION" #######
    
    Run Code Online (Sandbox Code Playgroud)

注意事项:

  • subnet部分应与在 Linux 客户机上收集的 IP 信息相匹配。在inet addr会中rangenetmask将匹配Maskoption broadcast-address将匹配Bcastoption domain-name-servers并且option domain-name将匹配收集与信息cat /etc/resolv.conf,并option routers会匹配Gateway来自route -n命令。

  • 我们想要分配一个静态 IP 地址,以便我们可以向 OS X 主机的hosts文件添加一个条目。地址必须在subnet定义的范围内。不可分配的地址是range子网部分中的地址、广播地址、fixed-addressfor host vmnet8、DNS 服务器和网关。而且我认为地址等于子网是不允许的。在这个例子中,子网是192.168.213.0因此可用的地址来自192.168.213.1 to 192.168.213.255less 192.168.213.128 to 192.168.213.245(范围)less 192.168.213.255(广播)less 192.168.213.1(主机vmnet8)less 192.168.213.2(网关和DNS服务器)。网络是地址192.168.213.3 to 192.168.213.127可用。


  • 在 OS X 主机上:hostDO NOT MODIFY SECTION下方创建一个新条目 。此条目将为 Linux 来宾分配一个静态 IP。hardware ethernet需要HWaddrifconfigLinux 客户机上匹配。为 选择一个可用的静态地址fixed-addressoption broadcast-addressoption domain-name-serversoption domain-name并且option routers需要匹配在给定的选项subnet的部分dhcpd.conf。(我们已经将其与在 Linux 客户机上收集的信息进行了匹配。)在此示例中,主机条目是:

    ####### VMNET DHCP Configuration. End of "DO NOT MODIFY SECTION" #######
    host serpents-hold {
        hardware ethernet 00:0c:29:53:bf:e5;
        fixed-address 192.168.213.3;
        option broadcast-address 192.168.213.255;
        option domain-name-servers 192.168.213.2;
        option domain-name localdomain;
        option routers 192.168.213.2;
    }
    
    Run Code Online (Sandbox Code Playgroud)
  • 在 OS X 主机上保存dhcpd.conf并关闭您的编辑器。

  • 在 OS X 主机和所有来宾上:关闭所有 VM 和 VMware。

  • 在 OS X 主机上:重新启动 VMware 服务:

    OSXHost$cd /Library/Application\ Support/VMware\ Fusion/ 
    OSXHost$sudo ./boot.sh --restart 
    
    Run Code Online (Sandbox Code Playgroud)
  • 在 OS X 主机上:查看Activity Monitor并确保每个命名的两个进程vmnet-dhcpd正在运行。(一个用于vmnet8NAT 网络,另一个用于仅主机网络。)如果您没有看到两者,则vmnet8/dhcpd.confOS X 主机上的文件可能有问题。修复该问题并重复重新启动 VMware 服务。

  • 在 OS X 主机上:启动 VMware 和 Linux 来宾 VM。

  • 在 Linux 来宾上 在来宾 VM 上检查设置是否符合预期:

    UbuntuGuest$ifconfig
    eth0      Link encap:Ethernet  HWaddr 00:0c:29:53:bf:e5  
              inet addr:192.168.213.3  Bcast:192.168.213.255  Mask:255.255.255.0
              inet6 addr: fe80::20c:29ff:fe53:bfe5/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:103 errors:0 dropped:0 overruns:0 frame:0
              TX packets:71 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:10961 (10.9 KB)  TX bytes:9637 (9.6 KB)
    lo <snip>    
    UbuntuGuest$cat /etc/resolv.conf
    nameserver 192.168.213.2
    domain localdomain
    search localdomain
    UbuntuGuest$route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    192.168.213.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0
    0.0.0.0         192.168.213.2   0.0.0.0         UG    100    0        0 eth0
    UbuntuGuest$
    
    Run Code Online (Sandbox Code Playgroud)
  • 在 Linux 客户机上:检查外部世界是否可达:

    UbuntuGuest$ping google.com
    PING google.com (72.14.213.104) 56(84) bytes of data.
    64 bytes from pv-in-f104.1e100.net (72.14.213.104): icmp_seq=1 ttl=128 time=47.6 ms
    64 bytes from 2.bp.blogspot.com (72.14.213.104): icmp_seq=2 ttl=128 time=48.7 ms
    64 bytes from 2.bp.blogspot.com (72.14.213.104): icmp_seq=3 ttl=128 time=48.2 ms
    ^C
    --- google.com ping statistics ---
    4 packets transmitted, 3 received, 25% packet loss, time 3093ms
    rtt min/avg/max/mdev = 47.687/48.223/48.714/0.491 ms
    UbuntuGuest$
    
    Run Code Online (Sandbox Code Playgroud)
  • 在 OS X 主机上:将主机名的映射添加到hosts文件:

    OSXHost$cd /etc
    OSXHost$sudo emacs hosts
    
    Run Code Online (Sandbox Code Playgroud)

    使用 Linux 客户机的主机名和上面分配的 IP 地址在 hosts 文件的末尾添加一行。

    192.168.213.2   serpents-hold
    
    Run Code Online (Sandbox Code Playgroud)
  • 在 OS X 主机上:保存文件并退出 emacs。

  • 在 OS X 主机上:测试 Linux 来宾是否可以通过主机名访问:

    OSXHost$ping serpents-hold
    PING serpents-hold (192.168.213.3): 56 data bytes
    64 bytes from 192.168.213.3: icmp_seq=0 ttl=64 time=0.169 ms
    64 bytes from 192.168.213.3: icmp_seq=1 ttl=64 time=0.244 ms
    ^C
    --- serpents-hold ping statistics ---
    2 packets transmitted, 2 packets received, 0.0% packet loss
    round-trip min/avg/max/stddev = 0.169/0.207/0.244/0.037 ms
    OSXHost$
    
    Run Code Online (Sandbox Code Playgroud)


has*_*emi 9

原始问题的一步答案是运行以​​下命令:

$ sudo apt-get install libnss-mdns

安装此软件包应立即启用该功能。然后,您将能够在your-vm-hostname.local. 这仅适用于 VM 的本地网络,这取决于您在虚拟化软件中的配置方式。

此功能被 Apple 称为 Bonjour,其他人称为 Zeroconf。它内置于 OS X 和 iOS 中。在 Windows 上获取它的最简单方法是安装 iTunes for Windows。