Intro To 'hostid' Command In Linux
2023-06-29 - By Robert Elder
I use the 'hostid' command to print out the current machine's 'host id':
hostid
and the output will look something like this:
12345678
Where Does 'hostid' Come From?
In the GNU Coreutils implementation of the 'hostid' command, you can see that all it does it call the 'gethostid' function which is implemented in glibc.
According to the man pages for the 'gethostid' function:
man gethostid
...
gethostid() and sethostid() respectively get or set a unique 32-bit
identifier for the current machine. The 32-bit identifier is intended to be
unique among all UNIX systems in existence. This normally resembles the
Internet address for the local machine, as returned by gethostbyname(3), and
thus usually never needs to be set.
...
The value returned by the 'hostid' command can be based on the contents of the file at '/etc/hostid':
xxd /etc/hostid
00000000: 7856 3412 ....
otherwise, it can be based on the current machine's IPV4 address, which could simply be the loopback address:
hostid
007f0101
A Legacy POSIX Feature?
Today, a 32 bit identifier is no longer adequate to achieve global uniqueness. This suggests that this 'host id' is mostly a legacy POSIX feature, first introduced in 1988. However, as of 2023 some software, such as OpenZFS, still relies upon the value of this hostid.
And that's why the 'hostid' command is my favourite Linux command.
Intro To 'stty' Command In Linux
Published 2023-10-04 |
$1.00 CAD |
Intro To 'nproc' Command In Linux
Published 2023-07-15 |
Intro To 'comm' Command In Linux
Published 2023-09-06 |
How To Force The 'true' Command To Return 'false'
Published 2023-07-09 |
A Surprisingly Common Mistake Involving Wildcards & The Find Command
Published 2020-01-21 |
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
Published 2019-08-01 |
Intro To 'chroot' Command In Linux
Published 2023-06-23 |
Join My Mailing List Privacy Policy |
Why Bother Subscribing?
|