How to modify the hostname in Linux

root's picture

Usually this is an easy task using the hostname command:

[root@blah ~]# hostname
blah
[root@blah ~]# hostname florian
[root@blah ~]# hostname
florian

But on some distributions, this procedure is not modifying the hostname permanently.

On Debian based systems you must:
1. edit /etc/hostname and put there whatever hostname you want to set;
2. run /etc/init.d/hostname.sh start

on RedHat based systems you have to:
1. edit /etc/sysconfig/network and put on HOSTNAME stanza whatever you want.
2. Reboot.

You can modify the hostname also via sysctl command:
to read: sysctl kernel.hostname
to modify: sysctl kernel.hostname=blah

Thou shalt not steal!

If you want to use this information on your own website, please remember: by doing copy/paste entirely it is always stealing and you should be ashamed of yourself! Have at least the decency to create your own text and comments and run the commands on your own servers and provide your output, not what I did!

Or at least link back to this website.

Recent content

root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root