What determines the Linux hostname?

The hostnameprogram performs a uname syscall, as can be seen from running:

strace hostname
...
uname({sysname="Linux", nodename="my.hostname.com", ...}) = 0
...

From the uname syscall man page, it says the syscall retrieves the following struct from the kernel:

  struct utsname {
               char sysname[];    /* Operating system name (e.g., "Linux") */
               char nodename[];   /* Name within "some implementation-defined
                                     network" */
               char release[];    /* Operating system release (e.g., "2.6.28") */
               char version[];    /* Operating system version */
               char machine[];    /* Hardware identifier */
           #ifdef _GNU_SOURCE
               char domainname[]; /* NIS or YP domain name */
           #endif
           };

So the domain name comes from the NIS / YP system, if we believe the comment. So more than likely, there may be a NIS / YP service on your network that is trotting back the name to you that is set by the ubuntu OS.


There are two independent(!) concepts of a hostname on a linux system.

There is whatever the kernel considers the local host name (as handled by the gethostname/uname and sethostname system calls) independent of any network connectivity - these mechanics would still exist if you built a kernel with no capability for TCP/IP networking.

There is one or more host names that are actually connected to TCP/IP (or other network stack - not all networking in the world is IP!) addresses the host has, and these are handled in userspace by the resolver library functions (part of libc), which will determine such a name by interpreting sources (local /etc/hosts file, DNS, NIS....) according to the rules you give them in the appropriate configuration files (/etc/nsswitch.conf, /etc/host.conf etc...).


Probably Ubuntu connected to the internet through your home router during the installation. For doing this, it reported its hostname to the router and obtained a temporary local IP.

When you now reboot into Fedora, it will connect to the same router to obtain its IP address, but the old lease created for Ubuntu is still valid. As it's the same machine with the same network card and the same hardware MAC address, it will reuse the same lease.

My guess is that the router sends the hostname on which the IP lease was registered along and Fedora picks that up.

Unfortunately I have no evidence or citation to support my answer, I can just speak with the personal experience of installing Ubuntu in dual-boot with Windows. Back then, Ubuntu refused to set the same hostname during the installation as the one I used in Windows, because it claimed that the name was alreday present in the network. Likely we have something similar happening here.

To verify if what I guess applies to your situation as well, try revoking your IP lease in your router's configuration interface and then reboot Fedora. If it no longer takes Ubuntu's hostname then, I should be right.