Samba/how-to/name resolution
Automatic resolution of Network Neighborhood names
Some explanation, for technical purists:
- Problem: How can we add Network Neighborhood machine names to the search space used by Linux's domain name resolver?
- Justification: This is needed so that commands which accept a domain name as input (e.g. ftp, ssh, mysql) can accept a machine name instead, removing the necessity to manually look up the machine's IP address. For example, I should be able to type ssh machinename instead of having to first look up machinename's IP address via other methods, and then paste or retype that address (both methods prone to error) after the ssh command.
Note: Under some circumstances, Samba appears to set itself up this way automatically, but results have been inconsistent.
I researched this extensively for many months and found many hideously complicated or otherwise inadequate solutions. It turns out, however, that there is quite a simple solution (which is probably trivially obvious to anyone with a solid understanding of how Linux networking is structured, and hence not worth mentioning):
- install winbind
- usually available in standard repositories; Ubuntu 6.06 and up have it
- this may not be necessary on some systems, e.g. Fedora 6 doesn't show winbind in its package repository, but the next step makes things work anyway
- edit /etc/nsswitch.conf
- change the "hosts" line to include "wins" before "dns" (see the examples)
This tells Linux's domain name resolver to check WINS before it checks DNS when resolving domain names. No further action should be required (you don't even have to restart the networking daemon); test the change by trying to ping a local machine by name.
The command nmblookup machinename returns an IP address, as will net lookup machinename. nmblookup apparently sends out a broadcast request ("anyone here named machinename?"), while net lookup checks a central list (presumably on the Samba master browser).
explanations
WINS is a method of domain name resolution, as is DNS. WINS (a protocol) originally used NetBIOS (another, lower-level protocol), but more recently has switched to using TCP.