Reach raspberry by name instead by IP address


15 posts
by GianfrancoPa » Wed Jan 09, 2013 7:18 am
Another question today...

I have installed a webserver on my raspberry that i can reach using his IP number, for example:

http://192.168.2.30

is possibile to do this?

http://myrasp-name/

Thanks you!!!
Posts: 62
Joined: Sun Jul 22, 2012 8:34 am
by Joe Schmoe » Wed Jan 09, 2013 7:31 am
Some say yes, some say no.

Some say that you can put something in one of the dhcp config files to cause the Pi to "export" a name to the local LAN.

Some say that there is this thing called "Zero Conf" that automagically makes everything work (and makes your breath smell sweet and your shoes to shine).

But none of this has ever worked for me.
Never answer the question you are asked. Rather, answer the question you wish you had been asked.

- Robert S. McNamara - quoted in "Fog of War" -
Posts: 2779
Joined: Sun Jan 15, 2012 1:11 pm
by GianfrancoPa » Wed Jan 09, 2013 7:44 am
If I read my router dhcp list, i see that my device uses a name "raspberrypi", but if I do http://raspberrypi/ on my browser, I retrieve error page. It's your same situation???

Zero Conf is the utility of raspbian wheezy where is possible to set many options?
Posts: 62
Joined: Sun Jul 22, 2012 8:34 am
by RaTTuS » Wed Jan 09, 2013 7:44 am
put the name in the place where your dhcp server is
http://www.catb.org/esr/faqs/smart-questions.html <- ask smart Questions
"That's not right, the badgers have moved the goalposts."
1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX - Prosliver FTW
User avatar
Posts: 5339
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
by Joe Schmoe » Wed Jan 09, 2013 8:11 am
GianfrancoPa wrote:If I read my router dhcp list, i see that my device uses a name "raspberrypi", but if I do http://raspberrypi/ on my browser, I retrieve error page. It's your same situation???

Yes. As you report, it shows up in my router DHCP table, but any attempts to use this name from other machines on the LAN (e.g., "ping raspberrypi") fail.

It could be a function of how good your router is - that some routers do indeed "publish" these names (the ones that show up in the DHCP table), but others (most), like yours & mine, do not.

Zero Conf is the utility of raspbian wheezy where is possible to set many options?


I guess. I know nothing about it. Some other posters, who were making a big to-do about it in another thread, will no doubt be posting on this thread soon.

I'm skeptical of anything that has the word "zero" in it...
Never answer the question you are asked. Rather, answer the question you wish you had been asked.

- Robert S. McNamara - quoted in "Fog of War" -
Posts: 2779
Joined: Sun Jan 15, 2012 1:11 pm
by GianfrancoPa » Wed Jan 09, 2013 8:15 am
Joe Schmoe wrote:
GianfrancoPa wrote:It could be a function of how good your router is - that some routers do indeed "publish" these names (the ones that show up in the DHCP table), but others (most), like yours & mine, do not.


Uhm, in my lan there are two devices that I can reach correctly using their names, like my NAS....
Posts: 62
Joined: Sun Jul 22, 2012 8:34 am
by pluggy » Wed Jan 09, 2013 12:31 pm
The easiest way is to put the name and IP address in the hosts file on the client machine. Even Windows has one.

http://www.howtogeek.com/howto/27350/be ... osts-file/

If your router isn't doing the business, you'd otherwise need extra software on the Pi.
Don't judge Linux by the Pi.......
User avatar
Posts: 2603
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
by rurwin » Wed Jan 09, 2013 1:03 pm
I agree. Unless you have a lot of PCs, then using the hosts files is the way to go.

Just make the IP addresses of all computers static and add the names and addresses to the hosts file of every computer.

Unlike the hostnames, static IP addresses are supported by almost every router on the market and it is easy to set up. Easier than doing it on Windows or Linux, and those are fairly trivial.

On Linux the hosts file is /etc/hosts and on Windows it is /windows/system32/drivers/etc/hosts. Both files have the same format.

If your router doesn't support static addresses, we'll tell you how to set the address in Linux or Windows, but of course then you'll have issues if you take your Pi or PC around to a mate's house.
User avatar
Forum Moderator
Forum Moderator
Posts: 2932
Joined: Mon Jan 09, 2012 3:16 pm
by efflandt » Thu Jan 10, 2013 12:42 am
Zeroconfig not actually rocket science or something mystic, it is a local broadcast name resolution somewhat similar to Windows file/printer sharing (samba in Linux). It is included in Apple computers, Bonjour from Apple can be installed in Windows to do it, and in Linux it is known as avahi. Of course it works best if each hostname is unique, so I set unique hostname in /etc/hostname and /etc/hosts of the SD card for each Pi. I use those names to ssh to each Pi, even if its dynamic IP changes.

While DNS might still not find computers on the LAN by name, applications can by the hostname followed by .local. Following were after doing sudo apt-get install avahi-daemon on a Pi.

From Windows 7 with Bonjour installed:

Code: Select all
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\efflandt>nslookup raspberrypi.local
Server:  dsldevice.domain_not_set.invalid
Address:  172.16.0.254

*** dsldevice.domain_not_set.invalid can't find raspberrypi.local: Non-existent
domain

C:\Users\efflandt>ping raspberrypi.local

Pinging raspberrypi.local [172.16.0.102] with 32 bytes of data:
Reply from 172.16.0.102: bytes=32 time=69ms TTL=64
Reply from 172.16.0.102: bytes=32 time=19ms TTL=64
Reply from 172.16.0.102: bytes=32 time=15ms TTL=64
Reply from 172.16.0.102: bytes=32 time=29ms TTL=64

Ping statistics for 172.16.0.102:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 15ms, Maximum = 69ms, Average = 33ms

From Ubuntu 12.04 Linux on a PC (avahi was installed by default):
Code: Select all
efflandt@XPS8100-1204:~$ host raspberrypi.local
host: '.local' is not in legal name syntax (empty label)

efflandt@XPS8100-1204:~$ ping -c2 raspberrypi.local
PING raspberrypi.local (172.16.0.102) 56(84) bytes of data.
64 bytes from raspberrypi.domain_not_set.invalid (172.16.0.102): icmp_req=1 ttl=64 time=13.6 ms
64 bytes from raspberrypi.domain_not_set.invalid (172.16.0.102): icmp_req=2 ttl=64 time=8.56 ms

--- raspberrypi.local ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 8.560/11.082/13.604/2.522 ms

efflandt@XPS8100-1204:~$ avahi-browse -at
+  wlan0 IPv6 XPS8100-1204 [78:e4:00:26:b8:ac]              Workstation          local
+  wlan0 IPv4 rpi8 [b8:27:eb:80:53:e5]                      Workstation          local
+  wlan0 IPv4 raspberrypi [00:9c:91:99:c0:29]               Workstation          local
+  wlan0 IPv4 XPS8100-1204 [78:e4:00:26:b8:ac]              Workstation          local
+  wlan0 IPv6 XPS8100-1204                                  Remote Disk Management local
+  wlan0 IPv4 rpi8                                          Remote Disk Management local
+  wlan0 IPv4 raspberrypi                                   Remote Disk Management local
+  wlan0 IPv4 XPS8100-1204                                  Remote Disk Management local

avahi-browse is included in avahi-utils package (which you can also install on Pi)
Posts: 359
Joined: Mon Dec 03, 2012 2:47 am
Location: Elgin, IL USA
by Twinkletoes » Thu Jan 10, 2013 12:53 am
zero conf / avahi / bonjour (all names for the same thing) also handles name conflicts - if you call three R-Pis by the same name "raspberry", you'll see the following network names:
raspberry
raspberry-1
raspberry-2

For lots of details here's a lecture by the guy who invented it for Apple (Stuart Cheshire) - http://www.youtube.com/watch?v=kgMVjEJiHDM
Posts: 210
Joined: Fri May 25, 2012 9:44 pm
by terrycarlin » Thu Jan 10, 2013 8:34 pm
When using zero conf / avahi / bonjour, the big trick is to append .local after the name.
So on your RPi that has a hostname of raspberrypi you would connect to it using raspberrypi.local

Code: Select all
ssh pi@raspberrypi.local
http://raspberrypi.local/index.html
 


On raspbian, you may need to install avahi. This provides the bonjour services.
Code: Select all
sudo apt-get install avahi-daemon
sudo apt-get install avahi-utils


Then you can do this:
Code: Select all
 avahi-browse -a -d local
to see all of the devices that advertise zero conf / avahi / bonjour services in the .local domain.

Don't forget to append that .local to the names.

it just works. It's not fussy at all.
If it ain't broke, take it apart and see how it works.
User avatar
Posts: 70
Joined: Thu Jun 14, 2012 10:42 pm
by GianfrancoPa » Fri Jan 11, 2013 6:59 am
RaTTuS wrote:put the name in the place where your dhcp server is


raspberrypi 192.168.2.37 B8:27:EB:--:--:-- Forever
Posts: 62
Joined: Sun Jul 22, 2012 8:34 am
by GianfrancoPa » Fri Jan 11, 2013 7:45 am
terrycarlin wrote:When using zero conf / avahi / bonjour, the big trick is to append .local after the name.
So on your RPi that has a hostname of raspberrypi you would connect to it using raspberrypi.local

Code: Select all
ssh pi@raspberrypi.local
http://raspberrypi.local/index.html
 


On raspbian, you may need to install avahi. This provides the bonjour services.
Code: Select all
sudo apt-get install avahi-daemon
sudo apt-get install avahi-utils


Then you can do this:
Code: Select all
 avahi-browse -a -d local
to see all of the devices that advertise zero conf / avahi / bonjour services in the .local domain.

Don't forget to append that .local to the names.

it just works. It's not fussy at all.



pi@raspberrypi ~ $ avahi-browse -a -d local
+ eth0 IPv4 raspberrypi Remote Disk Management local
+ eth0 IPv4 raspberrypi [b8:27:eb:--:--:--] Workstation local
+ eth0 IPv4 Brother MFC-J430W PDL Printer local
+ eth0 IPv4 Brother MFC-J430W UNIX Printer local
+ eth0 IPv4 Brother MFC-J430W Internet Printer local
+ eth0 IPv4 Brother MFC-J430W Web Site local

If I open, from a different pc on the lan,

http://raspberrypi/
http://raspberrypi.local/

I get alway error page...
Posts: 62
Joined: Sun Jul 22, 2012 8:34 am
by GianfrancoPa » Fri Jan 11, 2013 9:11 pm
I followed as described here: http://elinux.org/RPi_Advanced_Setup

in this way I can reach my raspberry using on the browser http://raspberrypi.local/

On Windows may be necessary to install The Bonjour Print Service from here: http://support.apple.com/kb/DL999

Now... If I wish to change the name in myname.local???
Posts: 62
Joined: Sun Jul 22, 2012 8:34 am
by GianfrancoPa » Sun Jan 13, 2013 12:07 pm
GianfrancoPa wrote:Now... If I wish to change the name in myname.local???


Solved: http://simonthepiman.com/how_to_rename_ ... rry_pi.php
Posts: 62
Joined: Sun Jul 22, 2012 8:34 am