The original way to do this was using
The man page notes that it's:
a 32-bit identifier... normally a DARPA Internet address for the local machine
i.e. it's the machine's IP address in hex.
This means it won't change just because somebody had to replace a broken network card.
It also means it's not guaranteed to be unique, for example if networking isn't configured, or the machine uses a private IP address.
In fact, it might not even be set, and can be changed by the superuser using
I can't find anything of much use in the
sysctl -a output besides
On OpenBSD there is
hw.uuid, but that's not available on FreeBSD.
After that, there are several commands that might help, including:
Most of these work by calling
ioctl on the relevant device.
If you need to do it in C, check out the source code for the above commands for more details.
You could also look at
libblkid to get the id of the root file system. Because they are ports, obviously neither of those are part of the base system, but one or the other might get installed as part of a standard desktop installation.
See also: Getting a unique id from a Unix-like system.