This is quite puzzling. Does anyone know where the hostname
command stores and reads hostname from?
I thought it was /etc/hostname but there is no such file on this Linux system that I'm using. I tried using strace to find where it was located but no read calls returned this information:
$ strace hostname 2>&1 | grep read
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340^\0\0\0\0\0\0"..., 832) = 832
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340\30\2\0\0\0\0\0"..., 832) = 832
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\320\16\0\0\0\0\0\0"..., 832) = 832
read(3, "nodev\tsysfs\nnodev\trootfs\nnodev\tr"..., 1024) = 248
read(3, "", 1024) = 0
Then I noticed it did uname syscall that returned this information:
uname({sys="Linux", node="server-name", ...}) = 0
A recursive grep in /etc/ returns nothing:
grep "server-name" -r /etc
Where does uname store this information? Just in memory?