If you are using Raspberry Pi under Raspbian for the first time and want to access it via SSH, you do not necessarily need the IP address. During the boot process, the IP address is displayed on the screen. Unfortunately, the IP address can change because the IPv4 address assignment by the DHCP server is always assigned a different address.
If you run a Raspberry Pi “headless” without a monitor and keyboard, then the connection can be quite annoying, because Raspberry Pi has a different IP address on almost every reboot. In general, it is then recommended to configure a fixed IPv4 address. But actually this is a complicated solution. Especially if a fixed IP address is not necessary for the application.
The Avahi daemon makes the host name of a machine known in the local network. Of course, this will only work if all computers on the network support Avahi or Zeroconf or Bonjour.
Then you can simply build connections with the hostname in the form of “hostname.local”. This works both in the browser and via SSH.
More information about Bonjour / Zeroconf / Avahi can be found at the end of the post
- Install Bonjour / Zeroconf / Avahi on Raspberry Pi (Raspbian Jessie).
- Check function of Bonjour / Zeroconf / Avahi on the network.
Solution: Install Avahi in Raspbian Jessie
Avahi is already installed under Raspbian Jessie. If not, then proceed as follows.
sudo apt-get update sudo apt-get install avahi-daemon
As of now, a Raspberry Pi can be reached by default under the host name “raspberrypi.local”. If you want to change the host name, then you can do that with “raspi-config”. However, the “.local” always remains. This top-level domain (TLD) identifies a host name in the local network and must always be specified in the addressing.
In the “Advanced Options” of raspi-config, there is the menu item “host name”, with which you can change the host name of the Raspberry Pi.
Solution: Test Avahi
To verify that Avahi works, you can install the Avahi tools and view the advertised services of other hosts on the network.
sudo apt-get install avahi-utils avahi-browse -a
This command does not end by itself. Finish it with “Ctrl + C”.
Troubleshooting: No more name resolution
If the host is no longer accessible by computer name, then it is recommended to uninstall and then reinstall the Avahi daemon. You can not do more.
sudo apt-get remove avahi-daemon sudo apt-get install avahi-daemon
In order for Raspberry Pi to be reachable under its hostname, the respective operating system must support Apple’s Bonjour service. This is not a problem with Mac OS and the usual Linux distributions. This is practically standard there. Things are different with Windows. Here you have to download the Bonjour drivers from Apple. Unfortunately, there is no viable solution for Android.
Zeroconf / Bonjour / Avahi is an announcement service. This means the service makes known the services offered by a computer on the local network. Typically, a printer will become aware of this in a local area network. Likewise, any computer on a network can advertise its hostname. In this way, a client learns from a server its host name and it is then possible to connect to the server via the host name.
Specifically, this means that the announcement includes the service, the host name, and the associated IPv4 and IPv6 addresses.
Zeroconf works on the basis of multicast messages. This means that the outgoing data packets do not have a specific receiver but go to all stations in the network. As a result, these messages are distributed across the network and occupy part of the bandwidth. This is not a problem for small local networks with few subscribers. For large networks, the Zeroconf messages can be a problem.
Zeroconf is a service that works on the application layer. This means that Zeroconf will not work until the configuration on the lower layers is complete. This refers to the IP configuration. For example, the configuration must be completed by DHCP for IPv4 and the automatic address configuration for IPv6. Alternatively, the IP addresses can be fixed, but that’s exactly what you want to avoid with Zeroconf.
Announcement of services and host names can not be done until the IP configuration is completed. This means that when a computer restarts, it takes a while for the hostname and services to be known on the local network. So if you start up a Raspberry Pi with Zeroconf / Bonjour / Avahi enabled, it takes a few seconds to connect to the hostname.
Zeroconf / Bonjour / Avahi
Zeroconf, Bonjour, and Avahi are self-configuring methods for adhoc networks based on IPv4 and IPv6. In essence, it is a collection of existing protocols based on IP, DNS, and NAT to automatically discover network services deployed in an IP network without the user having to manually configure anything.
Thus, Bonjour is also interesting in the embedded or IoT field, if sensors and actuators are to network and make known in the local network.
Bonjour, also known as Zeroconf (Zero Configuration Networking), is the successor to AppleTalk. Bonjour was founded by Apple in 2002 called “Rendezvous” and later renamed. Bonjour is not only available for Mac OS X, but also for Linux (Avahi) and Windows (Bonjour). Bonjour was released as open source by Apple under the Apache 2.0 license.
Bonjour solves various problems that occur in local networks.
- Assign IP addresses
- Assign names
- Advertise services
Whenever a computer system is connected to a network, addresses must be configured, services, directories and drives must be shared. At Bonjour, service providers voluntarily share their services (advertising) so that they can be found automatically by other stations. You can do without a central server that distributes the addresses, port numbers and server names. The services log in and out dynamically. At the same time, Bonjour stays in the background without any configuration overhead for the user.
How Zeroconf / Bonjour / Avahi work
Bonjour uses only single multicast DNS packets (mDNS) to exchange information. The clients exchange the Bonjour information to the port 5353 via the multicast address 184.108.40.206 (IPv4) or ff02 :: fb (IPv6). The Bonjour packages stay in the subnet. IP packets from the address range between 220.127.116.11 to 18.104.22.168 must not transmit IP routers beyond their own subnet. The rule here is that multicast packets must not be routed between the subnets.
One problem is that if you have multiple subnets on the network, then not all Bonjour packets will arrive anywhere. Only if all hosts work in the same subnet, then communication between all devices is possible with Bonjour.
So that Bonjour information is transmitted across subnet boundaries, one uses DNS-usual unicasts. The process is called Wide Area Bonjour (WAB) and requires a DNS server.
Originally, Bonjour was designed for home networks. But with the proliferation of MacBooks, iPhones and iPads, Bonjour spread even in larger network environments. But the more Bonjour hosts in the network, the more mDNS packets flood the network with subscriptions and deregistrations of services. That’s why Apple has partnered with an Internet Engineering Task Force (IETF) working group to create a new specification for larger enterprise and university networking environments.
Function: Assign IP addresses
Whenever you connect multiple devices via a switch, with a patch cable, via a WLAN access point or powerline adapter, the question arises as to how the devices get their IP addresses. It’s easy with IPv6. Here is the auto-configuration via SLAAC. Thus each host generates its own IPv6 address, which is only valid link-locally. For IPv4, Bonjour takes care of that. Again, the devices assign themselves addresses and Bonjour intervenes when it comes to address conflicts.
While IPv6 has the address range “fe80” for this purpose, the address range for link-local IPv4 addresses is “169.254.0.0/16”.
If a host specifies an IPv4 address for itself, it will broadcast it on the local network along with its hardware address. The other network subscribers then update their ARP caches (list with neighboring network subscribers).
If the IPv4 address is already being used by another user, this device must defend its address. The participant responds to the broadcast. In order to prevent the user from having to intervene manually, the subscribers leave an assigned IP address to other subscribers if they nevertheless wish to have it.
Function: assign name
In Bonjour, this feature is called Multicast DNS, or mDNS for short. This allows for stand-alone assignment of names on a network without user intervention and unicast DNS on a local network. For this purpose, the devices themselves have names. Often type designations, user-defined computer names or parts of user names. The checking process is similar to the assignment of link-local IP addresses. Whenever a conflict occurs, the name is automatically changed and checked again.
To distinguish between the names between mDNS and DNS, the names are given a “.local” as pseudo-top-level-domain (TLD). That is, “.local” is the TLD on a local network.
For name resolution, mDNS uses the same protocol as Unicast DNS. The client simply makes a DNS request to the multicast address “22.214.171.124” and gets back a response from the respective computer. It must be remembered that this address can only be reached in the respective subnet.
Function: advertise services
Not all network participants are clients who only access the Internet. There are also hosts offering services. For example, a network printer or a media center. Such devices make their services known via UDP. Because there is no special announcement / advertisement receiver, there are multicast addresses for IPv4 “126.96.36.199” and IPv6 “ff02 :: fb” and port 5353. All compatible devices listen to these addresses through service advertisements. Providers. It must be remembered that this address can only be reached in the respective subnet.
Tasks and exercises with Raspberrry Pi
Zeroconf / Bonjour / Avahi is an announcement service. This means the service makes known the services offered by a computer on the local network. Typically, a printer will become aware of this in a local area network. Likewise, any computer on a network can advertise its hostname. This works especially well in DHCP environments and if you want to avoid configuring and allocating static IP addresses.