[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Changing Hostname?



Jon N wrote:
> I recently installed Jessie on a new computer.  Now that I have the
> system up and running I decided that I would like to have a different
> hostname than the rather unimaginative  'localhost-01' I picked during
> install.  I used the "mate-network-admin" utility to change it, and
> checked /etc/hostname and saw that the change was reflected there
> also.

Changing the system hostname is a simple process.  But it depends upon
what is installed since often the hostname is embedded in the
configuration of a package.  For example the Postfix mail transport
agent needs to know the hostname in order for mail to work properly.
(I assume Exim does too but I don't run it and so don't know.)  So
does Apache.  And so forth.  Each of those packages that need to know
the hostname need to change.  Each of those changes are simple.  Just
make sure you look and change all of them.

Here are the places that need to be changed on every system.

  /etc/hosts
  /etc/hostname
  /etc/mailname

On systems running Postfix:

  /etc/postfix/main.cf

An unknown list of other files are possible depending upon what you
have installed and the configuration of those.  I would find them all
and change them.  Ignore binary files but note them as some files may
need to be recompiled and rebuilt.

  find /etc -type f -exec grep -l OLDHOSTNAME {} +

Typical files that you can ignore are encryption key .pub files.  The
hostname will be in the commend field and does not matter.  Ignore
them such as /etc/ssh/ssh_host_rsa_key.pub or other ssh_host_*_key.pub
files.  Or change them if you want to be completely clean.  Doesn't
matter.  Also ignore any /etc/lvm/* files if you are using lvm.
Ignore /etc/aliases.db but feel free to run 'newaliases' afterward to
recreate it with the new name.  (I don't know why the Berkeley db
builds the hostname in the .db file.)

You will probably end up ignoring more files than you care about.  If
you see something that is obviously a hostname then update it.  If in
doubt ask on this list.  Someone will either know about it or will
know how to figure it out.

> Then I rebooted.

Good.  So many daemons need to be restarted that it isn't worth it
trying to avoid the reboot.  Possible yes but not worth it.

> The display manager wouldn't load, leaving me with
> an almost blank screen (there was a blinking cursor in the upper left
> corner).

What display manager are you using?  There are many available.  This
sounds like the display manager you have used has configured the
hostname into its configuration.  I personally have not seen that
problem with display managers before.

> I switched to another virtual terminal, edited /etc/hostname
> back and was able to boot normally.

Note that you were almost certainly booting normally before.  The
hostname will not prevent the system from booting.  But starting a
graphical login manager is NOT something most of us would consider as
critical to the system boot process.

It sounds like a small part of your system, the graphical login
manager, doesn't start.  It not starting does not invalidate all of
the rest of the system.  I realize that to you not having a mouse
might be catastrophic but really it is only a small part of the
system. :-)

You mentioned mate-network-admin so I assume you are running mate.
But I don't know if that implies gdm for the login manager or not.  Or
is there a mate fork equiv of it?  If it were me I would log in at the
Linux console and start it manually and look for error messages.

  login: root
  password: ******
  root@localhost:~# service gdm restart
  ...possible errors might be seen here...

> Although when I just opened "mate-network-admin" again it still had
> the new name in there.  Apparently mate-network-manager changes
> /etc/hostname, but changing /etc/hostname doesn't reverse it
> completely???

Probably the mate-network-admin caches the answer you gave it and is
using the cached answer regardless of the actual system configuration.

> (I'm thinking I must have done something wrong, because that doesn't
> make sense).

I am thinking that you are using a opaque blackbox tool that doesn't
show what it is doing and therefore not learning anything useful about
the system.  Personally I despise those opaque wrapper blackbox tools
that try to make things easy for the user but keep them ignorant of
what is happening and prevent them from learning anything.  Everyone
who drives a car should know how to change a flat tire.  I believe
system adminstration is similar.

> Anyway, the main question is, how do i change the hostname for my system?

As described above.

> I did do some searching online, and so far I found that I have to change:
> 
> /etc/hostname
> /etc/hosts

Certainly those files need to be changed.  But also other files too.
Look for the previous hostname and see what files contain it on your
system.  This is where setting a very unique hostname on a system is
easier than "localhost" which will be everywhere.  If the system name
is "aeXiev7jtea0BieZ" then I am sure there will be no doubt! :-)

> then run the command
> 
> sysctl kernel hostname=NEW_HOSTNAME.

Hopefully you are missing a '.' in the middle there!

  # sysctl kernel.hostname=NEW_HOSTNAME
                 ^ missing dot

But that command isn't needed.  That is the same as:

  # hostname NEW_HOSTNAME

Why use the complicated Linux specific sysctl one when "hostname" is
the simpler one that has been around for decades on every Unix-like
system?

But again it isn't needed if you are going to reboot.  The above
changes the name that the kernel thinks is the system name in the
running kernel.  That is only done if you are going to try to avoid
rebooting and want to change the name on the fly dynamically.  This is
possible but IMNHO just not worth it.  To complete the task it would
be simplest to switch to single user mode, verify that all of the
interesting daemons that need to know the hostname have been stopped.
Daemons like Postfix (or Exim), Apache, basically any network aware
daemon which could be anything from a database daemon to a print
server daemon, almost anything.  Verify that they are all stopped.
Then start them back up again by switching from single user mode to
multi user mode.  But it isn't worth it.  Too easy to miss something.
Easier and safer to reboot.  That is guaranteed to be the normal
startup path for everything.

> There were also directions on how to change config files for some
> specific packages.  Am I missing anything?

  find /etc -type f -exec grep -l OLDHOSTNAME {} +

Then work from the list of files generated.

Bob

Attachment: signature.asc
Description: Digital signature


Reply to: