If you are tired of searching for the IP addresses of your devices that you frequently access remotely, for example, using SSH and other means on your home network, you can save yourself a lot of time by assigning the device an easy-to-remember local static address. In this article you will learn how to assign and use an address for your Raspberry Pi.
Why you want and should know?
Most likely, your home network uses DHCP IP assignment through a router or server, which means that every time a device leaves the network and returns, it may be assigned a new IP address. Even if you have a static IP address set for a frequently used device, such as your Raspberry Pi, you will have to keep memorizing that hard-to-remember number. And if you change the number for some reason, you may have to save a new number.
This is inconvenient, but there is a simple technical way to make your life easier. Why bother memorizing IP addresses when you can give your local devices easy-to-remember names like application-server.local or smarthome-bridge.local?
Some of you, especially those familiar with DNS, domain names and other network address structures, may now be wondering: Where is the rub?
Isn’t there an implicit risk or problem with simply adding a domain name to your existing network? At this point, it’s important to note the big difference between Fully Qualified Domain Names (FQDNs), which are officially recognized extensions for top-level domains, e.g., the .eu part of www.marcit.eu, which means that the corporate site marc.it is a commercial site, and domain names that are either not recognized by the global naming/DNS system or are reserved for use in private networks.
For example, .internal is not an FQDN at this time, there are no domains registered anywhere in the world that end in .internal. So if you configure your private network to use .internal for local addresses, there is no risk of a DNS conflict. However, that could change in the future, although the likelihood is low if .internal becomes an official FQDN and addresses ending in .internal are externally resolvable via public DNS servers.
The .local domain, on the other hand, has been officially reserved as a Special-Use Domain Name (SUDN) specifically for use on internal networks. It is never configured as an FQDN, so your custom local names can never conflict with existing external addresses e.g. application-server.local.
What you need for this?
The secret ingredient that makes the entire local DNS resolution system work is known as Multicast Domain Name Service (mDNS). Confusingly, there are actually two implementations of mDNS, one from Apple and one from Microsoft, present in the market. The mDNS implementation developed by Apple is the basis for the popular Bonjour service for discovering local networks. The Microsoft implementation is known as link-local multicast name resolution (LLMNR). The Microsoft implementation was never widely adopted because it did not adhere to various standards and posed a security risk in terms of the domains that could be captured for local use.
Because Apple’s mDNS implementation, Bonjour, enjoys much wider adoption, is better supported, and offers a wide range of applications for many platforms, this article addresses Apple’s implementation.
If you already have a machine running Apple’s OS X on your network, you don’t need to do anything but follow this guide to set things up on your Raspberry Pi or other Linux device. You can get started right away since your devices already support this.
If you’re using a Windows machine that doesn’t have iTunes installed, which would have a Bonjour client for mDNS resolution, you can fix the lack of native mDNS support by downloading Apple’s Bonjour Printer Service utility. Although the download page gives the impression that it is a printer-only tool, it actually adds mDNS Bonjour support for Windows.
Install Raspberry Pi Bonjour support
The first thing you need to do is either invoke a terminal on your Pi or connect to the remote terminal via SSH. Once you are in the terminal, take a moment to update your system with apt-get.
$ sudo apt-get update
$ sudo apt-get upgrade
After the update is complete, it is time to install Avahi – a small open-source mDNS implementation. The Avahi daemon ensures that the hostname of a device is advertised on the local network. This only works safely if everyone on the network supports Avahi, Zeroconf or Bonjour. Type the following command at the command prompt:
$ sudo apt-get install avahi-daemon
Once the installation process is complete, you do not even need to reboot the device. Your Raspberry Pi will immediately start detecting local network requests for its hostname at raspberrypi.local.
Again, to clarify, the part that comes before the .local extension is always the hostname of the device. If you want your Raspberry Pi to be named application-server.local, for example, you simply need to change the Pi’s hostname. This can be done by selecting the Hostname option under Advanced Options in raspi-config. Here is the article to set up a small web server using Docker, a practical example also for use on a Raspberry Pi.
Now call the new .local address on the machine from which you want to access the device.
Done! The address smarthome-brige.local will now resolve to the IP of your Pi. From now on, any application or service that previously required the IP address of the Raspberry Pi can use the .local address instead.