Page 1 of 1

[SOLVED] Change hostname

PostPosted: Aug 1st, '17, 09:54
by xtapetae
Is there a howto on how to change the hostname? I did not find something in this forum and the wiki, but may be I have overlooked it. In that case I would be grateful if someone would give me a pointer.

AFAIK this change has to be done at two points:
The file /etc/hostname contains "localhost" per default and can be changed to the new hostname, e.g. "mybox"
The file /etc/hosts contains "127.0.0.1 localhost" by default. It needs to be changed to "127.0.0.1 localhost mybox" (assuming the above example name).
I found out that it also may be changed via Mageia Control Center under Network & internet → Others → Hosts definitions by giving the new hostname as an alias. But that still leaves you with the necessitiy to manually change /etc/hostname. Is that correct?

Re: Change hostname

PostPosted: Aug 1st, '17, 13:05
by wintpe
it can be set by assigning a hostname to the dhcp record as well, in your router if it supports it.

if you are using static ip allocation (ie manually setting each hosts ip) then the correct entry in /etc/hosts is

staticipaddress shortname shortname.domainname anyotheraliasforhost


all routers are different so without knowing your router well i cant comment, but if you were using isc dhcp on a linux dhcp server then this would be easy to do

you would have a stansa for each host, with its ipaddress, macaddress, hostname and any other info you wanted to pass in the dhcp packet.

some people use rasberrypies for this, if their router does not support it, but that's only really worth while if you have many hosts, like i do.

if you only have one linux workstation id suggest use a static setup, if in fact you need a hostname.

if your workstation is simply a client of the network, having a hostname does not bring you much benefit

regards peter

Re: Change hostname

PostPosted: Aug 1st, '17, 13:14
by nigelc
This is the way that works:
su
Password.
Code: Select all
hostnamectl set-hostname NEW_HOSTNAME


Cheers
Nigel..

Re: Change hostname

PostPosted: Aug 1st, '17, 19:08
by doktor5000
xtapetae wrote:I found out that it also may be changed via Mageia Control Center under Network & internet → Others → Hosts definitions by giving the new hostname as an alias. But that still leaves you with the necessitiy to manually change /etc/hostname. Is that correct?

Actually by adding your new hostname as alias that way to /etc/hosts that does not change your hostname, that only changes what 127.0.0.1 resolves to.
And yes, to change your hostname you should change /etc/hostname as mentioned by Nigel. And for completeness, you can do the same via manahosts - see https://wiki.mageia.org/en/Mageia_6_Rel ... #ManaTools

Please mark the thread accordingly by editing the topic of the first post and prefix it by [SOLVED], thanks

Re: Change hostname

PostPosted: Aug 1st, '17, 23:07
by xtapetae
Actually by adding your new hostname as alias that way to /etc/hosts that does not change your hostname, that only changes what 127.0.0.1 resolves to.


Thanks for the answer and sorry for the follow up question which however is intimately related to my first post: In case I change my (static) hostname would I want to include to what 127.0.0.1 resolves to? In other words, should I add the new hostname to /etc/hosts as an alias? Or would you recommend to rather leave it untouched?

Re: Change hostname

PostPosted: Aug 1st, '17, 23:49
by doktor5000
You don't need to add the primary hostname to /etc/hosts as an alias for localhost, but most people will do that and when Mageia sets the hostname during the first network configuration it will also add it there IIRC.

Re: Change hostname

PostPosted: Aug 2nd, '17, 00:45
by xtapetae
A last note to this topic: IIRC including the new hostname as an alias in /etc/hosts was the proposed solution to the problem of various programs (among them emacs, libreoffice, sendmail, midnightcommander) starting up extremely slowly for some problem with looking up hostname. Unfortunately I failed to take a note about the source of this information (however there are various discussions on this showing up if you google for something like hostname linux slow emacs). In any case; it *may* be a solution if one experiences slow program starts after having set a new hostname. Unfortunately I lack the technical background to make a judgement here. I note it just for the sake of completeness.