1

cat /etc/hosts returns two results:

127.0.0.1  Localhost    
127.0.1.1  [mycomputersname].[city].[state].[domain].net  (brackets for anonymity)

When I run hostname, it returns [mycomputersname] without the .*.* etc etc

Whenever I run sudo, it tells me it can't resolve [mycomputersname]

If I manually change the hosts table to remove the .*.* etc, then it works fine. Until it changes it back at some point (reboot?) and it starts all over again. What is going on here and what can I do to fix it? Thanks!

Apologies if this is a dumb question. I'm very new to Linux.

muru
  • 197,895
  • 55
  • 485
  • 740
ztpsec
  • 11
  • 1

1 Answers1

2

Try this /etc/hosts line:

127.0.1.1  [mycomputersname].[city].[state].[domain].net mycomputersname

You can specify aliases this way.

hostname uses the /etc/hostname file to get its output (among other sources). You could set the fully-qualified domain name as the hostname as well:

hostnamectl set-hostname [mycomputersname].[city].[state].[domain].net
muru
  • 197,895
  • 55
  • 485
  • 740
  • Also, be sure to add "localhost" to the same line. Much software tries to find an IP address for "localhost". Having two lines beginning with 127.0.0.1 confuses the software (which one does it pick? How does it know?). – waltinator Sep 29 '14 at 19:47
  • @waltinator That's why this line use 127.0.1.1, and 127.0.0.1 is localhost. – muru Sep 29 '14 at 19:47