Karaoke
Posts: 3
Joined: Wed Mar 20, 2013 12:41 pm

Host Name Resolution

Wed Mar 20, 2013 12:51 pm

I have finally got my Pi up and running with 2013-02-09-wheezy-raspbian and have set it up with a static IP address and it all seems to work (I can even access the internet).

However I am unable to resolve the names for machines on my network! I can ping etc by IP address but not be name.
So ping 192.168.2.4 gets responses
ping Windows7 returns ping: unknown host Windows7
ping Windows7.Belkin is an unknown host as well
I know I could add the machines to the Hosts table except most of the machines are using DHCP and so their IP changes.

What am I doing wrong?

for info:
ipconfig on windows7 gives
Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . : Belkin
Link-local IPv6 Address . . . . . : fe80::7cc9:3d76:f6e3:e301%10
IPv4 Address. . . . . . . . . . . : 192.168.2.4
Subnet Mask . . . . . . . . . . . : 255.255.0.0
Default Gateway . . . . . . . . . : 192.168.2.1

On the Pi
/etc/network/interfaces is
auto lo

iface lo inet loopback
#iface eth0 inet dhcp

iface eth0 inet static
address 192.168.198.129
gateway 192.168.2.1
netmask 255.255.0.0
broadcast 192.168.255.255
dns-nameservers 192.168.2.1

texy
Forum Moderator
Forum Moderator
Posts: 5161
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Host Name Resolution

Wed Mar 20, 2013 1:06 pm

It seems there are many ways to string a cat.
Try these methods. You may need to reboot your pi and/or your router for them to take effect :

Edit /etc/hostname as follows:
cd /etc
nano hostname
nano is a Linux editor. Change the line raspberrypi to your chosen name for your server.
This is essential anyway if you have more than one Raspberry Pi.
Then save the file with [Ctrl]+O and exit nano with [Ctrl]+X.
Then edit /etc/hosts as follows:
nano hosts
Add the lines (the first line may already present but commented out with a # symbol):
127.0.0.1 localhost
10.0.0.97 localhost
10.0.0.97 raspberrypi

Note - change 10.0.0.97 to your chosen ip address and raspberrypi to whatever you want to call it.
This was copied from a tutorial on setting up the pi as a webserver created by kaspencer.

Hope this helps,
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: Host Name Resolution

Wed Mar 20, 2013 1:14 pm

You get Windows name resolution for free when you install samba:

Code: Select all

sudo apt-get install samba
... or at least other machines can see the RaspPi, I'm not certain the RaspPi can see Windows machines, but I imagine they can.

For Mac OS/X name resolution, you need avahi. If you have both ecosystems, use avahi and install iTunes on the Windows PCs.

Karaoke
Posts: 3
Joined: Wed Mar 20, 2013 12:41 pm

Re: Host Name Resolution

Wed Mar 20, 2013 2:02 pm

Thanks for the swift replies however

I have Samba installed and can successfully access the Pi from my Windows machine :D
however my problem is the opposite way round I'm trying to access a windows machine from the Pi using the Windows machine name (Windows7 in this case) which acquires its IP address using DHCP.

I have (as a workaround) added the machine to the Pi's hosts table but that will only work until the DHCP server gives the Windows machine a different IP address (which happens once every day or so)

Any help/suggestions appreciated

DBryant
Posts: 281
Joined: Sat Feb 02, 2013 12:41 pm
Location: Berkshire, UK

Re: Host Name Resolution

Wed Mar 20, 2013 2:19 pm

If Multicast DNS name resolution is installed on systems in your network then you can refer to your hosts by name simply by appending .local to the end i.e. an ad-hoc .local domain is crerated for you.. So if your system's name is pi, then it will respond to names like pi.local. Try:

ping pi.local

where pi is your name, and see if it works. If not, try installing libnss-mdns with:

sudo apt-get update
sudo apt-get install libnss-mdns

See http://packages.debian.org/sid/libnss-mdns

And then repeat the ping. No longer do you need to know IP addresses, and its independent of Samba.

Do the same on any other system in your network. In Windows this will work too, as long as you have iTunes installed. And if you don't have ITunes, then Google 'Bonjour print services' and install that. The open a command terminal on the Windows box and try 'ping pi.local' and it should resolve the IP address auto-magically.

Karaoke
Posts: 3
Joined: Wed Mar 20, 2013 12:41 pm

Re: Host Name Resolution

Wed Mar 20, 2013 6:19 pm

Finally sorted it (I hope)
Turns out I needed to install winbind and then tweak /etc/nsswitch.conf
and change the hosts: line to read
hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4 wins

which I found here:
http://rasspberrypi.wordpress.com/2012/ ... -hostname/

The only problem I then found was that some of my machines needed their network settings tweaked to not add the domain suffix to their names. But at least it's fixed :-)

Return to “Troubleshooting”