Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a Ubuntu Server 9.04 image set up in VMWare Fusion 3.0.0, using the NAT option for the guest's network connection. From the Mac host, I can ssh to the linux guest just fine using it's IP address, but I would like to be able to refer to it by hostname for convenience. ie:

mac-host:~ ssh user@linux-guest.local

I had a similar setup using Parallels a couple years ago, but I don't remember how it was set up. It may have "just worked".

Any suggestion on how to make this work?

share|improve this question
add comment

5 Answers

up vote 10 down vote accepted

EDIT The first version of instructions I posted caused conflicts with the nameserver and gateway that VMware put on vmnet8. This version corrects the issue.

Software versions:

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

What I have done:

  • During creation of the VM, set networking to NAT.

  • On Linux Guest: Run ifconfig to get the hardware address HWaddr, broadcast address Bcast, IPv4 internet address inet addr, and mask Mask being used.

    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>
    
  • On Linux Guest: Lookup the nameserver information

    UbuntuGuest$cat /etc/resolv.conf
    nameserver 192.168.213.2
    domain localdomain
    search localdomain
    
  • On Linux Guest: Lookup the gateway address: (Listed in the Gateway column of the line with 0.0.0.0 as Destination.)

    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
    
  • On OS X Host: Edit the dhcpd.conf file for vmnet8 (The NAT virtual switch) to assign a static IP address to the Linux Guest. (Use your editor of choice on the fourth line)

    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
    
  • On OS X Host: The file will start out looking something like:

    # 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" #######
    

Things to note:

  • The subnet section should match the IP information gathered on the Linux Guest. The inet addr will be within range, netmask will match Mask, option broadcast-address will match Bcast, option domain-name-servers and option domain-name will match the information gathered with cat /etc/resolv.conf and option routers will match Gateway from the route -n command.

  • We want to assign a static IP address, so that we can add an entry to the OS X Host's hosts file. The address must be within the subnet defined. Addresses that are not available to assign are the ones within range in subnet section, the broadcast address, the fixed-address for host vmnet8, the DNS server and the gateway. And I think the address equal to subnet is not allowed. In this example, the subnet is 192.168.213.0 So the available addressees are from 192.168.213.1 to 192.168.213.255 less 192.168.213.128 to 192.168.213.245 (range) less 192.168.213.255 (broadcast) less 192.168.213.1 (host vmnet8) less 192.168.213.2 (gateway and DNS server). The net is that addresses 192.168.213.3 to 192.168.213.127 are available.


  • ON OS X Host: Create a new host entry below the DO NOT MODIFY SECTION. This entry will assign a static IP to the Linux Guest. hardware ethernet needs to match HWaddr from ifconfig on the Linux Guest. Pick an available static address for fixed-address. option broadcast-address, option domain-name-servers, option domain-name and option routers need to match the options given in the subnet section of dhcpd.conf. (Which we have already matched against information gathered on the Linux Guest.) In this example the host entry is:

    ####### 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;
    }
    
  • On OS X Host Save dhcpd.conf and close your editor.

  • On OS X Host and all Guests: Shutdown all VMs and VMware.

  • On OS X Host: Restart the VMware services:

    OSXHost$cd /Library/Application\ Support/VMware\ Fusion/ 
    OSXHost$sudo ./boot.sh --restart 
    
  • On OS X Host: Look in Activity Monitor and make sure that two processes each named vmnet-dhcpd are running. (One is for the vmnet8, the NAT network, the other is for the host only network.) If you don't see both, there is probably a problem with the vmnet8/dhcpd.conf file on the OS X Host. Fix that and repeat the restart of VMware services.

  • On OS X Host: Start VMware and the Linux Guest VM.

  • On Linux Guest On the guest VM check that settings are as expected:

    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$
    
  • On Linux Guest: Check that the outside world is reachable:

    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$
    
  • On OS X Host: Add a mapping for the hostname to the hosts file:

    OSXHost$cd /etc
    OSXHost$sudo emacs hosts
    

    Add a line to the end of the hosts file using the Linux Guest's hostname and the IP address assigned above.

    192.168.213.2   serpents-hold
    
  • On OS X Host: Save file and exit emacs.

  • On OS X Host: Test that the Linux Guest is reachable by hostname:

    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$
    
share|improve this answer
    
This is great...if your on an OSX host. Wish I could find the windows equivalent somewhere. –  tj111 Sep 15 '10 at 14:19
1  
Great info. Thanks. 2 updates for v4.x 1. Location of dhcpd.conf is now: "/Library/Preferences/VMware Fusion/" 2. In Fusion 4, the networking service does not run when Fusion is shut down. To restart the networking service, restart Fusion. –  sym3tri Apr 30 '12 at 18:33
add comment

This Mac feature is called Bonjour. To enable the equivalent on Ubuntu, you need to install a package called libnss-mdns by entering this command in the Ubuntu guest machine:

sudo apt-get install libnss-mdns

Once the packages are installed, the feature should work instantly.

The feature only works within the local network. If you are using NAT networking, this means that the feature will only work within the host machine and its VMs. If you want the feature to work across your larger home network, you need to use Bridged mode so that your VM participates in your home network by getting its IP address, etc, from the home networks router/DCHP server.

share|improve this answer
    
Using this, I need to append '.local' to the name of the guest machine, e.g. ubuntu-guest.local, when I refer to it from the host side. That aside, this works wonderfully! –  Nathaniel Waisbrot Aug 16 '13 at 20:21
    
@NathanielWaisbrot That's true. That's what the original poster wanted. –  Ahmad Sep 5 '13 at 20:49
add comment

You could configure zeroconf using Avahi, which should allow the client to identify itself on a network without DNS registration.

share|improve this answer
add comment

assuming you just want to login over a command line, why not create an ssh config file? i do something like this for my vm.

# ~/.ssh/config
Host linux-box    
Hostname localhost
Port 8822

then i can

mac-box:~ ssh linux-box
share|improve this answer
add comment

If you are using NAT, it may try to register with DNS servers, however to computers other than the host, it's IP will be the same as your machines and can cause a few problems.

I would recommend that you switch to bridged networking as this will give it its own IP address and to any machine, it will look and feel like any other machine on the network. If you set up all the IP settings correctly (or use DHCP), it should automatically register and you should not have a problem doing anything on any port via IP or hostname.

share|improve this answer
1  
Yes I think that would work but I'd prefer a stable private network. The VM is on a laptop that moves around and sometimes doesn't have an internet connection. If I used bridged-mode, I wouldn't be able to contact it when the host was offline. –  amrox Nov 18 '09 at 16:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.