How to resolve hostnames in linux
This last month I have grown very fond of Ubuntu. I have installed it on some 4 PCs around the house and at work, and it works very well (also, I love Beryl). While I haven’t completely switched from Windows, Linux beats Windows on a server by far.
One of the things I could never get to work is local hostname resolution under Ubuntu. None of the PCs I installed it on could resolve hostnames in the local network (LAN, for those of you who didn’t understand that other term). I searched for days and days, and finally I found how to do it somewhere, but now I don’t remember where. So, I am documenting it here, so that mainly I don’t forget, and in hope that it will be useful to some of you.
To enable WINS resolution in Ubuntu, do the following:
Edit the /etc/nsswitch.conf file, and change this line:
hosts: files dns
to this:
hosts: files wins dns
Then do a sudo aptitude install winbind to install winbind, and everything should work like a charm. I am also fairly certain that you can use samba as a WINS client (or server, whatever it is), but I haven’t tried it, since this solution works. If I ever do, I’ll post it here.
/two-bits
It is my understanding that the winbindd daemon installed with this package is the one from the samba packages... it is (an optional) part of Samba. So this actually IS the Samba WINS server.
Further, I wonder if you have static IP addresses in your network. I am not so sure this will work for people who have dynamically assigned IP addresses, as so many home users do. Most cable modems and home routers are set up for dynamic IP address assignment with their built-in DHCP servers. If folks try this and it works for a while then starts to fail, it is probably because they do not have static IP addresses.
/end-two-bits
peace!
Submitted by Mojo (not verified) on Sat, 25/11/2006 - 00:20.mojo
Hmm, well, I don't know if this is the Samba server, but the options in smb.conf haven't been touched, and I meant that you might be able to change those to get it to work without installing Winbind. As for the failure, I have been using it for over a month with all-dynamic hostnames and it's working fine so far.
Submitted by Stavros on Sat, 25/11/2006 - 10:20.---
Vidi, Vici, Veni.
Worked on Debian 4.0 too
Submitted by Anonymous (not verified) on Mon, 23/04/2007 - 23:01.Ah, good. I wouldn't be surprised if it worked on many more distributions, actually.
Submitted by Stavros on Tue, 24/04/2007 - 00:04.---
Vidi, Vici, Veni.
This sollution worked perfectly well for me under Fedora 6 as well.
Submitted by Freddie (not verified) on Sat, 02/12/2006 - 12:55.i can ping my local macnines, vnc into them with the actual pc name rather than the ip address etc. just wot i was looking for, thanks.
Submitted by jet2230 on Wed, 18/04/2007 - 02:08.I read a lot about this in various forums. Did not know it was this simple!!
Thanks for tip. Its useful even after such a long time. It worked flawlessly on Ubuntu Gutsy Gibbon (7.10).
Submitted by Gary (not verified) on Thu, 05/06/2008 - 20:12.You're welcome :) I'm surprised they haven't enabled this by default yet, actually...
Submitted by Stavros on Thu, 05/06/2008 - 20:13.The order DOES make a difference here. If you have this file configured as above, then DNS will resolve before wins, and you'll often get timeouts or errors on the local network.
For example, if you use OpenDNS, your local names will not resolve at all.
The line should read:
hosts: files wins dns
This way, local wins names are resolved before dns, and everything works quickly and error free.
Submitted by dmizer (not verified) on Thu, 07/08/2008 - 08:26.You are quite right, sir. I have corrected this, thank you.
Submitted by Stavros on Wed, 27/08/2008 - 16:17.Thank you SO much. I have been searching this for several hours, while it's so simple. I wonder why this is not clearly explained in some official or semi-official doc and howto. (I also wonder why so many alleged-ubuntu-geeks do not plainly admit that they don't know instead of hiding themselves behind heaps of complications.)
In Hardy 8.04, the change to be made in /etc/nsswitch.conf is a bit different:hosts:
hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4
to this:
hosts: files wins mdns4_minimal [NOTFOUND=return] dns mdns4
As far as I can see, a search domain is added by default: I can ping my Morgenstern pc without completing its name with 'workgroup.com'.
Submitted by Anonymous (not verified) on Mon, 08/09/2008 - 09:15.Hello ,
Thank you for this information but can you help me ?
I couldnt do this :
Edit the /etc/nsswitch.conf file, and change this line:
hosts: files dns
Best regards,
Submitted by Hobi (not verified) on Mon, 15/06/2009 - 10:24.Hi, probably you need to sudo (be super user/root)
just add
sudo
before the command
example
sudo nano /etc/xxxxxxxxxxxx
will ask for your password :)
tahts because normal users dont have write permission to that folder
cheers
Submitted by Rodrigo Marras (not verified) on Sat, 18/07/2009 - 14:51.Thanks very much. Been struggling to do this for ages in Ubuntu 9.04. Worked first time.
Submitted by Anonymous (not verified) on Fri, 21/08/2009 - 23:21.Only problem is pinging my xp box takes a couple of seconds to reeturn the packets although the trip times are normal. Pinging my other Ubuntu box performs normally.