There are several answers on how to change hostname of Ubuntu, and all of them propose to do "the same changes" to /etc/hosts
. "The same" stands for "the same as in /etc/hostanme
". But unfotunately, these files have completely different formats, and they can't be changed in "same" manner.
So, the question is: what to write in hosts
to have hostname myname
?
Currently my hosts
contains:
127.0.0.1 localhost
and some IPv6 stuff which I don't understand.
So, should I replace localhost
with myname
, really?
Yes, really. The
/etc/hosts
file is just a map that links IPs to hostnames. If you want to be able to do things likessh myname
and have that runssh localhost
, you need to add a line that identifies localhost (127.0.0.1) asmyname
:You could just replace
localhost
withmyname
, but then things likessh localhost
would fail andlocalhost
is pretty standard. So just add another line as shown above.