Change the mDNS name on your Raspberry Pi

Raspbian Stretch Lite

If you’ve installed an image like Raspian, OctoPi, or RetroPi you may have noticed that it started broadcasting an mDNS entry for raspberrypi.local on your network for ease of access. Now if you’re like me you’ve probably collected a couple for various projects so to avoid having to assign static IPs to each one, here’s how to update your pi to have a unique hostname instead.

You’ll need access to your pi’s terminal, either through the system’s gui or SSH. I logged into mine using Ubuntu as a Windows 10 Subsystem.

$ ssh pi@raspberrypi

And entered the default password “raspberry”

First I updated the password to something new using:

$ passwd

Next there’s two files that need to be edited.
The first is /etc/hosts. I’m using vi, but if you prefer nano, or another editor it’s just fine as long as it’s a plain text editor.

$ sudo vi /etc/hosts

The file should look something like this:       localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters       raspberrypi #change this line to your desired hostname.

Change the last line where it says “raspberrypi” ( to your desired hostname. I’m using “node-red” for my new Node-RED server. If you’re using vi, once you’ve edited the file you can press Ctrl+C, then “:wq!” to “write” and “force quit” the vi editor. If you screw up the file at any point because your keyboard isn’t agreeing, or you’re having a hard time with the vi commands you can always “Ctrl+C :q!” to force quit without saving and start over.

The next file you’ll need to edit is is /etc/hostname. This file should just contain the hostname “raspberripi” which you can follow the same procedure as you used in the hosts file to edit to the same name used before.

This is all read up by the Avahi daemon on boot, so for the last step you’ll just need to reboot your pi.

$ sudo reboot

After a couple of minutes the pi should be back up and running and you should now be able to access your system using the new address. For my new project my Raspberry Pi Zero W is now node-red.local.