[SOLVED] Change hostname

This forum is dedicated to advanced help and support :

Ask here your questions about advanced usage of Mageia. For example you may post here all your questions about network and automated installs, complex server configurations, kernel tuning, creating your own Mageia mirrors, and all tasks likely to be touchy even for skilled users.

[SOLVED] Change hostname

Postby xtapetae » Aug 1st, '17, 09:54

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?
Last edited by xtapetae on Aug 2nd, '17, 00:46, edited 1 time in total.
xtapetae
 
Posts: 15
Joined: Aug 29th, '13, 21:10

Re: Change hostname

Postby wintpe » Aug 1st, '17, 13:05

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
Redhat 6 Certified Engineer (RHCE)
Sometimes my posts will sound short, or snappy, however its realy not my intention to offend, so accept my apologies in advance.
wintpe
 
Posts: 1204
Joined: May 22nd, '11, 17:08
Location: Rayleigh,, Essex , UK

Re: Change hostname

Postby nigelc » Aug 1st, '17, 13:14

This is the way that works:
su
Password.
Code: Select all
hostnamectl set-hostname NEW_HOSTNAME


Cheers
Nigel..
nigelc
 
Posts: 266
Joined: Aug 28th, '11, 09:35

Re: Change hostname

Postby doktor5000 » Aug 1st, '17, 19:08

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
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 18018
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: Change hostname

Postby xtapetae » Aug 1st, '17, 23:07

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?
xtapetae
 
Posts: 15
Joined: Aug 29th, '13, 21:10

Re: Change hostname

Postby doktor5000 » Aug 1st, '17, 23:49

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.
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 18018
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: Change hostname

Postby xtapetae » Aug 2nd, '17, 00:45

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.
xtapetae
 
Posts: 15
Joined: Aug 29th, '13, 21:10


Return to Advanced support

Who is online

Users browsing this forum: No registered users and 1 guest