In the few years I've been using Linux as my main system, specifically Fedora, I've always seen my hostname set to just "localhost", with the exception of when I connect to some networks and it becomes my IP. Today I experienced the following behavior which I'm having trouble understanding though.

I set up an Ubuntu installation on another partition of my laptop, setting a computer name / hostname during the Ubuntu install. When I rebooted back into Fedora though, Fedora had updated my hostname to the name I set in the Ubuntu install.

I always thought the hostname was configured and stored on the partition of the distro installation, and indeed the contents of /etc/hostname on Fedora still read "localhost.localdomain", but running the hostname command shows the new hostname. Both installs share an efi boot partition, but are otherwise discrete. I'm wondering from where and why the Fedora install is reading the new hostname?


3 Answers 3


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

strace hostname

e="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. */
               char nodename[];   /* Name within "some implementation-defined
                                     network" */
               char release[ystem 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 */

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

  • 5
    This isn't true, see the hostname(1) man page which explains how the hostname is set and returned. Despite the similarity in name the NIS/YP domain name has nothing to do with the FQDN/DNS domain name which is returned by the resolver. If you haven't configured NIS/YP then the NIS/YP domain name will be unset.
    – bodgit
    May 18, 2017 at 22:04
  • Is "nodename" the field you care about? Would be in line with unix nostalgy to still consider IP networks an optional and implementation defined thing :) May 19, 2017 at 8:07

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.

  • It is indeed possible for a DHCP client to send a hostname to the server, or read a hostname from the server. Most everything does the first (though when the hostname is set to "localhost" it's unlikely to have much effect :). Reading a hostname from the DHCP server is possible with Linux DHCP clients, but my understanding was this support was not always enabled (e.g.). Interesting to hear that a more recent Fedora seems to do this.
    – sourcejedi
    May 19, 2017 at 11:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .