Friday 17 September 2010

Adding NETBIOS lookup support to "ping"

A guy today asked in the Linux community why he was not able to ping Windows machines by using just their Windows hostnames from Linux when he could do the same from windows. So I decided to write this small HOWTO for others who might be asking the same question.

Most Linux distributions come with the ping utility, but unlike the Windows ping command, it does not get replies if we used a Windows HOSTNAME or NetBIOS name.

The usual workaround most people would do is add the hostnames in their Linux machine's /etc/hosts file in the format

IP.AD.RE.SS hostname

Example:
192.168.1.15 winfoo
But this will become too cumbersome to maintain when the machine's IP Address changes or when there are too many hosts for you to handle manually. The other option is a local DNS but that is unnecessary in a small network.

The simplest solution to this lies in the nsswitch.conf configuration file.

Open the file with your favourite Editor (you need to use sudo or be root to edit) and look for a line that begins with "hosts:". On my system this was:

hosts: files dns
Just add the wins at the end. So my line will be

hosts: files dns wins
Now try pinging a windows Machine using only the windows Hostname and it should be working all fine.