1

https://en.wikipedia.org/wiki/Unique_local_address

https://www.rfc-editor.org/rfc/rfc4193#section-3.2.2

http://www.sixxs.net/tools/grh/ula/list/

I have been looking for a local script to generate ULAs; there are many online generators (and a few bad/broken) ones; I wanted a local script.

https://www.vultr.com/tools/mac-converter/

http://ben.akrin.com/?p=1347

Community
  • 1
  • 1
  • I don't know of a script to generate the Global ID, but there are instructions in the RFC. See [this question](https://networkengineering.stackexchange.com/q/48488/8499). – Ron Maupin Feb 25 '18 at 16:48

3 Answers3

1

There already exists this github repository with a bash script that generates ULA. It is written to run interactively and asks for mac address (and confirm an ntp query).

hlovdal
  • 26,565
  • 10
  • 94
  • 165
0

This should be run on a physical machine; not on an emulated system or virtual env. Tune the if variable according to needs.

if=eth0
t="$(ntptime | grep "time " | head -n1 | awk '{print $2}')"
EUI_48="$(ip a s dev $if | grep "link/ether" | awk '{print $2}')"
EUI_64="$(ipv6calc --action prefixmac2ipv6 --in prefix+mac --out ipv6addr :: $EUI_48 | sed 's/^:://')"
conq="$(echo "$t $EUI_64" | tr -d ".: ")"
sha1="$(for x in $(echo "$conq" | sed 's/\(..\)/\1 /g') ; do printf "\x${x}" ; done | sha1sum | awk '{print $1}' | tail -c 11 | sed 's/\(..\)/\1 /g')"
ULA="$(echo $sha1 | awk '{print "fd" $1 ":" $2 $3 ":" $4 $5 "::/48"}')"
echo "$t $EUI_48 $EUI_64 $conq=> $ULA"

By the way, ipv6calc is designed to produce the link local address this way:

ipv6calc --action prefixmac2ipv6 --in prefix+mac --out ipv6addr fe80:: $EUI_48

If you don't want to install ipv6calc, here is a function to convert EUI-48 into EUI-64: https://gist.github.com/mej/592da948323fc58455c1

  • This does not answer the question: Link local addresses (`fe80..`) are most definitly *not* ULA addresses (`fd..`). See my answer for a simple way to generate valid ULAs in bash (without any external tools). – Tenders McChiken Aug 13 '23 at 09:35
  • I forgot why I added a part about generating LLs, but the first bit of code produces a /48 ULA. – Benoit-Pierre DEMAINE Aug 24 '23 at 15:38
-1

You can easily generate valid ULAs in bash by only using the builtin printf and the special Bash variable $RANDOM:

printf "fd%x:%x:%x:%x::/64\n" "$(( $RANDOM/256 ))" "$RANDOM" "$RANDOM" "$RANDOM" 

Running this several times on my own machine give me a bunch of freshly-minted (and more importantly, valid) ULA addresses with random subnet ids:

fd45:364c:99:6690::/64
fd19:59c8:7e73:30d7::/64
fd0c:4ebe:60ce:7a02::/64
...

If you want to only use one ULA network and multiple subnet ids per site, leave out the last two bytes and assign the subnet id manually as required:

fd45:364c:99::/64
fd45:364c:99:1::/64
fd45:364c:99:2::/64

Before you use a ULA, make sure to run the command a couple of times to make sure that your $RANDOM is giving out random values. If it isn't, start a fresh bash session and make sure you're not doing anything to the random variable.

Tenders McChiken
  • 1,216
  • 13
  • 21
  • I have asked for ULAs, which are by definition /48. An answer containing /64 can not answer my request. You should not generate a big bunch of /64 in a variety of /48, but generate ONE /48 for you, and always stay in it. At most one /48 per site to not exhaust the fd00::/8 pool too fast. After 20y of IPv6, I am still staying inside my old 3 ULAs; and in practice I am using only one of them. The fix for your code is probably : printf "fd%x:%x:%x::/48\n" "$(( $RANDOM/256 ))" "$RANDOM" "$RANDOM" – Benoit-Pierre DEMAINE Aug 24 '23 at 15:46
  • @Benoit-PierreDEMAINE ULAs can only be /48 if you ignore the mandatory subnet ID which - as far as I know - must be 16 bits (see [relevant rfc](https://datatracker.ietf.org/doc/html/rfc4193#section-3.1)). Because of this, ULA subnets are /64 by definition. I'm more than willing to be corrected (if I'm wrong) but then, my answer stays `/64`. – Tenders McChiken Aug 26 '23 at 06:24
  • Also, your question did not mention your /48 requirement. It did not mention any subnetting requirements so I don't think it's appropriate or honest to vote my answer as not useful. That said, it's up to you. Cheers. – Tenders McChiken Aug 26 '23 at 06:30