0
[root@localhost ~]# hostname hello
[root@localhost ~]# hostname
hello
[root@localhost ~]# cat /etc/hosts
127.0.0.1   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?

Warren Young
  • 71,107
  • 16
  • 178
  • 168
xmllmx
  • 1,750
  • 2
  • 19
  • 29

1 Answers1

2

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.

countermode
  • 7,373
  • 5
  • 31
  • 58
  • My distro is fedora, which file is used to store the information? – xmllmx Sep 29 '16 at 15:20
  • According to this question http://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