Uname -n vs hostname

hostnameposix

What is the difference between uname -n and hostname? Are there any real differences in what they return? Are there any differences in availability on different OSes? Is one of them included in POSIX and the other not?

Best Answer

There is no difference. hostname and uname -n output the same information. They both obtain it from the uname() system call.

One difference is that the hostname command can be used to set the hostname as well as getting it. uname cannot do that. (Normally this is done only once, early in the boot process!)