Skip to content

Instantly share code, notes, and snippets.

@cyqsimon
Last active October 5, 2025 18:07
Show Gist options
  • Select an option

  • Save cyqsimon/cb5f452a2ebd5b2971de8582a0f17f55 to your computer and use it in GitHub Desktop.

Select an option

Save cyqsimon/cb5f452a2ebd5b2971de8582a0f17f55 to your computer and use it in GitHub Desktop.
RFC 4193 IPv6 subnet selection algorithm one-liner

Based on RFC 4193 and this guide.

This should work anywhere coreutils is available.

date +%s%N | tr -d '\n' | cat - /etc/machine-id | sha1sum | cut -c 31-40 | sed 's|^|fd|; s|.\{4\}|&:|g; s|$|:/64|'

Explanation

date +%s%N # get current unix timestamp at nanosecond accuracy
| tr -d '\n' # trim trailing new line character
| cat - /etc/machine-id # concatenate with local machine ID
| sha1sum # compute SHA-1 digest
| cut -c 31-40 # take the least significant 40 bits (10 hex digits)
| sed 's|^|fd|; s|.\{4\}|&:|g; s|$|:/64|' # append 'fd'; insert separators; append subnet mask
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment