Ubuntu can not ping Host Name but can ping IP?

37,232

The problem described here may not be related to DNS at all.

You have to know that Windows can resolve the Windows hostname to its IP via other mechanisms than standard DNS : NetBIOS lookup, WINS, ...

As you said you have Samba installed on your Ubuntu, this is probably what's happening. On all of your Windows machine, it is possible, out-of-the-box, to have the Windows name resolved to its IP address. As Samba is installed on Ubunut, for your Windows PC, they see the Ubuntu PC as a Windows PC and the same resolution is possible.

You tell that you run net view on Windows and you see your Ubuntu PC, so the NetBIOS name is well published on your network, so it works from Windows.

To achieve the same behaviour on Ubuntu as on Windows, you have to install and configure additional pieces of software. What you need is to add a lookup library that will allows Ubuntu to convert NetBIOS names to IP. This library is contained into the libnss-winbind package.

As any other Ubuntu packages, you install it by doing sudo apt-get install libnss-winbind. May be the library is already installed, you can check it presence by doing dpkg -l|grep libnss-winbind.

Once the library is installed, you have to enable it in the /etc/nsswitch.conf file. This file is the configuration file for the NSS (Name Service Switch), which defines from which sources Linux is able to resolve hostname, usernames, groupnames and so on.
In this file, you already have a line starting by hosts:, probably looking like this

hosts:          files dns

This tells your system to first look into the /etc/hosts file and then into the configured DNS to resolve hostnames.
You have to modify this way :

hosts:          files dns wins

Note that the order of the words files, dns and wins are important. First, the system will check the local file for resolution, then will ask the DNS server and finally, if not yet found, will perform NetBIOS lookup.

Once this is updated, to function correctly, you also need to have the winbind service running. The package containing it is a dependency of libnss-winbind, so it has been installed along it.
Do service winbind start to activate it.

Share:
37,232

Related videos on Youtube

user2805313
Author by

user2805313

Updated on September 18, 2022

Comments

  • user2805313
    user2805313 over 1 year

    well I just went into the Ubuntu world for administration. I found similar threads, except, I am able to ping my own Host name and IP address and my windows can ping my linux host name, but Ubuntu can not ping the windows hostname.

    Problem:

    • I have 4 windows computers and I have 1 Ubuntu Computer
    • My windows Computer can ping Ubuntu Computer by Hostname and by IP address. Also, Net View (cmd prompt) displays the host name of Ubuntu Computer.
    • Ubuntu Computer can only Ping by IP address only Not by hostname. I installed Samba as well.
    • Ubuntu Computer can ping itself by IP address and by Hostname
    • I can use arp command and will display all the computers IP on the network, but only by IP address.

    How is it that I can only ping by IP address and not by hostname to the windows computers? But Ubuntu can ping itself by IP address and Hostname and windows computers can ping Ubuntu by hostname as well?

    • jrg
      jrg almost 10 years
      Try the hostname in ALL CAPS. that could be the trick.
    • user2805313
      user2805313 almost 10 years
      Yeah, I tried that, but no luck. =( Someone said to add .local at the end. My co workers said I have to configure the network to point at the router in order for it to understand. So I will try that out, and if it works, I'll go ahead and post the answer
    • Wolverine
      Wolverine over 9 years
      It may be a DNS server problem. Configure DNS server settings correctly. Maybe these two sources can help you. serverfault.com/questions/389522/…. askubuntu.com/questions/23011/….
  • Tristan
    Tristan over 8 years
    Don't forget to use sudo with the service winbind start command.