Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.).

share|improve this question
    
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". – Sh3ljohn Jan 11 at 12:31
    
@StephenKitt Exactly, does this have another name in Linux systems? – Sh3ljohn Jan 11 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 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 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. – Sh3ljohn Jan 11 at 12:43
up vote 23 down vote accepted

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).

share|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 at 14:19

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.

share|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). – jww Jun 17 at 4:19
    
NetBIOS name is still a network name, even if it's different from a domain name. – Dmitry Grigoryev Jun 17 at 8:24

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]

share|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. – Sh3ljohn Jan 11 at 12:33
10  
user-chosen name? that sounds like hostname to me. – Bibek_G Jan 11 at 12:35
1  
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 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. – Sh3ljohn Jan 11 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. – Sh3ljohn Jan 11 at 12:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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