[root@localhost ~]# hostname hello
[root@localhost ~]# hostname
[root@localhost ~]# cat /etc/hosts   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@localhost ~]# 

The command line output is as above.

Why is the hostname output different from what is found in /etc/hosts?


The system hostname is not set using the file /etc/hosts.

The hostname is set using the system configuration management system. Where the hostname is stored persistently depends on the distribution. For instance, on my kali machine the hostname is stored in the file /etc/hostname from where it is read during startup; on my gentoo machine it is stored in /etc/conf.d/hostname.

  • My distro is fedora, which file is used to store the information? – xmllmx Sep 29 '16 at 15:20
  • According to this question unix.stackexchange.com/q/162393/64248 and its answer you use the command hostnamectl. Beyond that, I am not at all familiar with Fedora. – countermode Sep 29 '16 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.