The flexible way: Set up avahi / zeroconf. Zeroconf is ‘a set of techniques that automatically creates a usable Internet Protocol (IP) network without manual operator intervention or special configuration servers.’[3]. Avahi is an implementation of zeroconf which ‘ships with most Linux and *BSD distributions’ [4], but not the Raspberry Pi’s Debian distribution. Zeroconf will be familiar to Apple users as Bonjour and is pretty clever tech which means that things Just Work when sharing stuff across computers on a network. In this context, it means that once we’ve set it up on the Raspberry Pi, we’ll be able to address it as:
raspberrypi.local
regardless of what IP address it’s been assigned on your local network. This is handy if its IP address is likely to change regularly, and even means we’ll continue to be able to address it if we’re on a different network (say, shuffling between home and work networks).
Information in this section largely gathered from 4dc5.
- Install avahi with the following commands on the Raspberry Pi:
sudo apt-get install avahi-daemon
and then on older Debian installs:
sudo update-rc.d avahi-daemon defaults
or on newer Raspbian installs:
sudo insserv avahi-daemon
(if in doubt, you’re probably on the newer one).
- Create a configfile for Avahi at /etc/avahi/services/multiple.service. I did this with the following command:
sudo pico /etc/avahi/services/multiple.service
The contents of this file should be something like the following, courtesy of aXon on the Rasperry Pi forums:
<?xml version="1.0" standalone='no'?> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> <service-group> <name replace-wildcards="yes">%h</name> <service> <type>_device-info._tcp</type> <port>0</port> <txt-record>model=RackMac</txt-record> </service> <service> <type>_ssh._tcp</type> <port>22</port> </service> </service-group>
- Apply the new configuration with:
sudo /etc/init.d/avahi-daemon restart
The Raspberry Pi should now be addressable from other machines as raspberrypi.local, for example:
ssh pi@raspberrypi.local
- Get Windows to play nice with avahi
If you’ve done the first steps correctly and you open up PuTTY and you try to address your Raspberry Pi as raspberrypi.local; it will tell you:
This happens for a very good reason: your Windows PC can’t interpret the UDP-datagrams avahi sends and most firewalls don’t even allow them to get read. So you’ll have to do a couple of things extra to get it working.
- Get Bonjour for Windows
http://support.apple.com/kb/DL999 Just install it, the quick next next next next procedure will suffice. Now your computer is able to interpret the UDP datagrams which are multicasted by the Raspberry Pi. But we’re not out of the woods just yet; if you try to ping to your Raspberry Pi:C:\Windows\System32>ping raspberrypi.local Ping-request cannot find host raspberrypi.local. Check the name and try again.
- Tell your firewall: trust me, I’m an engineer.
Stereotypically, the firewall forbids us to have some fun. First of all, the 5353 UDP port is blocked on most firewalls, so you have to add an exception for it. Also, you’ll have to grant Internet access to the mDNSresponder.exe. This way, whenever your computer tries to connect with a host *.local, mDNS sends a multicast over the local subnet to ask whether anyone calls himself *.local. If mDNS isn’t granted network access, nothing gets multicasted and nobody answers the phone.
Note: If you have the McAfee firewall, you’ll also have to enable UDP control. If it isn’t enabled, all UDP datagrams are ignored. - Enjoy the pleasure of typing raspberrypi.local in PuTTY
After these steps, you should be able to ping to raspberrypi.local and even address it that way in PuTTY. YMMV, if you’re still having troubles at this point, try to ping to raspberrypi.local with the firewall turned off. If it works: hey presto, you’ve got your culprit, and you can start an educated Google search.