Skip to content

Instantly share code, notes, and snippets.

@leiless
Created September 29, 2021 08:07
Show Gist options
  • Save leiless/ec62fa42aa63db8aa7e9f2f69686ec5c to your computer and use it in GitHub Desktop.
Save leiless/ec62fa42aa63db8aa7e9f2f69686ec5c to your computer and use it in GitHub Desktop.
Linux shell - how to generate random MAC address
#!/bin/bash
set -eufo pipefail
#set -x
tr -dc a-f0-9 < /dev/urandom | head -c 12 | sed -r 's/(..)/\1:/g;s/:$//1'
@leiless
Copy link
Author

leiless commented Sep 29, 2021

Example output

8e:04:2a:54:fd:ef
62:9e:0d:20:f8:88
01:4d:c3:72:d3:1b
bf:11:a9:bb:00:dd

NOTE

You need to turn off pipefail when assign result of tr -dc a-f0-9 < /dev/urandom | head -c 12 | sed -r 's/(..)/\1:/g;s/:$//1' into a variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment