I am trying to give a hostname along the lines of PiComputer_User1 however I am encountering the following error: unable to resolve host (hostname) : Name or service not known

I have added static ip routes and the appropriate hostname to /etc/hostname and /etc/hosts

I am able to ping and connect via ssh using the ip address and routes which I added, however I still get the error whenever I try to install anything

Additionally when I try to use hostname -i I get the error Name or service not known

In particular I am noticing that if I use hostname it returns the hostname as PiComputerUser1 where there should be an underscore between computer and user

To confirm one more time I am using the correct naming convention in hosts and hostname

Does anyone know why I am getting errors, and if I am allowed to use underscores in hostnames to begin with? Thank you!

  • your question about a Linux computer is off topic here ... this site is for questions that are specific to Raspberry Pi
    – jsotola
    Nov 9, 2022 at 21:48
  • Did you reboot after changing the hostname?
    – Dougie
    Nov 9, 2022 at 22:13
  • Use a hyphen (-) instead of the underscore. Nov 9, 2022 at 22:19

1 Answer 1


The text string in a hostname must be from ASCII characters. It includes the upper or lower case (A to Z or a to z), digits (0 to 9), the dot symbol (.), and the hyphen symbol (-).

NOTE it is inadvisable to edit /etc/hostname or /etc/hosts manually.
Change using raspi-config.

Getting this wrong can cause networking errors on Debian systems (due to attempts to use FQDN).

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.