All the results of my searches end up having something to do with hostname or uname -n. I looked up the manual for both, looking for sneaky options, but no luck.

I am trying to find an equivalent of OSX's scutil --get ComputerName on Linux systems. On Mac OS X, the computer name is used as a human-readable identifier for the computer; it's shown in various management screens (e.g. on inventory management, Bonjour-based remote access, ...) and serves as the default hostname (after filtering to handle spaces etc.).

  • I might be wrong, but defining the name of the computer as its network name means that it doesn't have a fixed name, right? When you install a Linux or OSX on a machine, you usually choose a name for that computer (which is the default network name I assume). For example my laptop might be named "FooBar" but when I connect to a network at work I get a hostname such as "machine42.work.localnetwork".
    – Jonathan H
    Jan 11, 2016 at 12:31
  • @StephenKitt Exactly, does this have another name in Linux systems?
    – Jonathan H
    Jan 11, 2016 at 12:37
  • 4
    @Sh3ljohn what purpose does computername is osx serve? I don't think there's any equivalent in linux system.
    – Bibek_G
    Jan 11, 2016 at 12:39
  • Did you give some name other than hostname when installing that computer? Try searching for that name in /etc: grep -ri 'name' /etc
    – ptman
    Jan 11, 2016 at 12:42
  • @Bibek_G I would like to use this to identify the machine on which I am running from a software of mine. UUID is insufficient because there might be several OS's installed on the same disk which in turn run on the same machine.
    – Jonathan H
    Jan 11, 2016 at 12:43

5 Answers 5


The closest equivalent to a human-readable (and human-chosen) name for any computer running Linux is the default hostname stored in /etc/hostname. On some (not all) Linux distributions, this name is entered during installation as the computee’s name (but with network hostname constraints, unlike macOS’s computer name). This can be namespaced, i.e. each UTS namespace can have a different hostname.

Systems running systemd distinguish three different hostnames, including a “pretty” human-readable name which is supposed to be descriptive in a similar fashion to macOS’s computer name; this can be set and retrieved using hostnamectl’s --pretty option. The other two hostnames are the static hostname, which is the default hostname described above, and the transient hostname which reflects the current network configuration.

Systemd also supports a chassis type (e.g. “tablet”) and an icon for the host; see systemd-hostnamed.service.

  • 1
    But this file is often used to set hostname and uname -n, and @Sh3ljohn explicitly wanted to avoid the output of those two commands. Jan 11, 2016 at 14:19

You could use the sudo dmidecode | grep -A3 '^System Information' command. This command reads information from the BIOS and the hardware. Example from my machine:

System Information
    Manufacturer: LENOVO
    Product Name: 20BHA06YGB
    Version: ThinkPad W540

Sources: [1]

  • I don't think this is what I am looking for; this requires admin rights and gives you information about the hardware, not about a user-chosen name at the time you installed the OS on that machine.
    – Jonathan H
    Jan 11, 2016 at 12:33
  • 15
    user-chosen name? that sounds like hostname to me.
    – Bibek_G
    Jan 11, 2016 at 12:35
  • 2
    Sorry, I got that wrong. I will leave the answer anyway. The only user chosen name using the Linux distributions I know is the hostname.
    – jnodorp
    Jan 11, 2016 at 12:38
  • @Bibek_G This is why I can't find the answer to my question, on OSX these are two different things. I am looking for the name I entered when I installed Linux on that machine, which I assume would be the default network name.
    – Jonathan H
    Jan 11, 2016 at 12:39
  • @jschlichtholz Of course, this answer might be useful to someone else, but as I said to Bibek_G, I am looking for what might be the default network name then.
    – Jonathan H
    Jan 11, 2016 at 12:40

Strictly speaking, there is no such thing as network-unrelated "computer name" in Linux, and I actually fail to see the purpose of naming computers which are not on the network.

The reason why your computer has different strings in /etc/hostname, /etc/hosts and uname -n is that DHCP protocol has facilities to provide a hostname along with IP address to a new host. "machine42.work.localnetwork" looks exactly like a name the DHCP server would pick. This string is then saved and returned by gethostname calls.

See also:

How do I change the computer name? (tl;dr echo computername > /etc/hostname) - that's what happens when you pick a name during the installation.

How do I change the hostname without a restart? (tl;dr hostname computername) - that's what happens when you get a DHCP lease with a host name.

  • "Strictly speaking, there is no such thing as network-unrelated "computer name" in Linux" - Doesn't it depend on the service? For example, I think the Windows equivalent is the NetBIOS name. Its the friendly name without the domain parts, and it may be different from the host part of a domain name (fully qualified or not).
    – user56041
    Jun 17, 2016 at 4:19
  • NetBIOS name is still a network name, even if it's different from a domain name. Jun 17, 2016 at 8:24
  • tools.ietf.org/html/rfc1178 advises NOT to use a domain name for the name of your computer. One computer can provide a server for multiple domain names. In this case hostname can only supply one of the servers. Oct 1, 2020 at 5:33

The other answers say there is no Linux equivalent, even though there actually is. It's called the "Pretty hostname". Run the following command to get it:

hostnamectl --pretty
  • 4
    hostnamectl requires SystemD. The pretty information is stored in /etc/machine-info
    – fpmurphy
    Jun 22, 2020 at 1:47
  • 2
    +1 I think this should be the chosen answer. --- Wikipedia says: "A hostname is a domain name which has an associated DNS record." Combine this with tools.ietf.org/html/rfc1178 which advises NOT to use a domain name for the name of your computer. This means one should also not use a hostname for the name of your computer. What gives when a single computer tries to run two networks at the same time? In this case the hostname can't be the hostname for them both. hostname is clearly overloaded, trying to be both a DNS hostname, and a machine name at the same time. Oct 1, 2020 at 6:46

one liner:

hostnamectl | egrep -i "Static hostname" | awk '{print $NF}'

You must log in to answer this question.

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