Skip to Content
gnux

hostidx

Print the numeric identifier for the current host.

Mirrors GNU hostid. Run it as hostidx, or as gnux hostidx.

Synopsis

hostidx [OPTION]

GNU reference

Description

hostidx prints the host's 32-bit identifier in hexadecimal, eight digits wide, as gethostid(3) returns it. On Linux that is the contents of /etc/hostid when the file exists, and otherwise a value glibc derives from the first IPv4 address the host name resolves to. On macOS and the BSDs it is the kern.hostid sysctl, which may be zero. Windows has no gethostid, so hostidx derives the value from the host's address there too, as glibc does; with no address it prints 00000000. The identifier is not guaranteed to be unique.

Permissions

Reads /etc/hostid on Linux when it exists. Needs no permissions.

Use cases

  • Reporting the identifier that some license managers bind to.
  • Telling machines apart in a log when the hostname is not enough.

Flags

      --help      display this help and exit
      --version   output version information and exit

Examples

hostidx
Output
a8c002d7

Record the host name and identifier together in a log line

echox "$(hostnamex) $(hostidx)" >> machines.log

Exit status

StatusMeaning
0success: every operand was processed
1failure: an operand could not be processed (diagnosed on standard error), or a command-line mistake

Help in the terminal

hostidx --help                # options, first examples, exit status
gnux help hostidx             # this page: the full manual
gnux help hostidx --OPTION    # one option in depth, with its examples

See also

On this page