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 '16 at 12:31
  • @StephenKitt Exactly, does this have another name in Linux systems? – Jonathan H Jan 11 '16 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 '16 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 '16 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 '16 at 12:43

The closest equivalent to a human-readable (and human-chosen) name for a 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 computer's name (but with network hostname constraints, unlike Mac OS X's computer name).

| improve this answer | |
  • But this file is often used to set hostname and uname -n, and @Sh3ljohn explicitly wanted to avoid the output of those two commands. – roaima Jan 11 '16 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]

| improve this answer | |
  • 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 '16 at 12:33
  • 14
    user-chosen name? that sounds like hostname to me. – Bibek_G Jan 11 '16 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. – jschlichtholz Jan 11 '16 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 '16 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 '16 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.

| improve this answer | |
  • "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 '16 at 4:19
  • NetBIOS name is still a network name, even if it's different from a domain name. – Dmitry Grigoryev Jun 17 '16 at 8:24

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
| improve this answer | |
  • 3
    hostnamectl requires SystemD. The pretty information is stored in /etc/machine-info – fpmurphy Jun 22 at 1:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.