I changed the hostname of my laptop (running raspbian x86) using raspi-config to "test". My username is "pi". However when I view /etc/hosts, the below is obtained:    localhost
.    testpi

I have two questions:

  1. Should that not be test localhost on the first line?
  2. Why is it testpi and not test only?

Hoping someone can clear my confusion :)


On a fresh raspbian jessie install, /etc/hosts is configured the same way. Here's what mine looks like on my RPi named "desktop". I manually edited it to replace "raspberrypi" with "desktop":   localhost
::1     localhost ip6-localhost ip6-loopback
ff02::1     ip6-allnodes
ff02::2     ip6-allrouters   desktop

There's more info on the debian site:

The IP address in the second line of this example may not be found on some other Unix-like systems. The Debian Installer creates this entry for a system without a permanent IP address as a workaround for some software (e.g., GNOME) as documented in the bug #719621.

In short: If you are assigning the RPi a permanent IP address, can put that address in place of This is a debian thing, not a RPi thing.

[Edit] Regarding the discrepancy in names between /etc/hosts and /etc/hostname, it doesn't seem to originate with raspi-config. The relevant lines that it uses to update the hostname are:

if [ $? -eq 0 ]; then
  echo $NEW_HOSTNAME > /etc/hostname
  sed -i "s/*$CURRENT_HOSTNAME/\t$NEW_HOSTNAME/g" /etc/hosts

The resulting name should be identical in both files, at least using raspbian jessie on ARM.

  • Understood. But in my case I never edited /etc/hosts manually. I used raspi-config and I don't understand why in my case how testpi and not test was attributed to By the way is it normal for raspi-config to edit /etc/hosts automatically? By what I can recall, I did it manually in previous versions (just updated raspbian...) – iLW Jul 6 '17 at 20:58
  • What do you see in /etc/hostname? I'm expecting it to be "testpi". If not, something is definitely amiss with raspi-config. I normally do manual edits to /etc/hosts and /etc/hostname when renaming systems, so can't say for sure how that tool does it. – bobstro Jul 6 '17 at 21:14
  • UPDATE: I just took a look at raspi-config, and all it does is overwrite /etc/hostname with the name you entered, and replaces the entry in /etc/hosts with the same value. – bobstro Jul 6 '17 at 21:20
  • I just checked on the system. "/etc/hostname" is set to test whereas the value in "etc/hosts" is set to testpi. So confusing why my sys tem does that. I would like to precise that I am on raspbian x86 on a netbook however.. – iLW Jul 6 '17 at 21:23

Instead of adding the hostname to the first line as you propose like below (which will work):   localhost  test

You may want to have the name associated with a specific IP address, by adding something like this to the /etc/hosts file:   test

The advantage of the second version over the first is that other devices on your LAN can connect to your Pi. The IP address always resolves as localhost and so is not routable. So for example, if you are running a web server, other computers could connect using the IP and if AVAHI is running or you make a similar entry in their hosts file they could connect to your host using the hostname.

I do not know how you wound up with testpi and not just test on the last line, but you can certainly change it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.