How to use shell to derive an IPv6 address from a MAC address

awkipv6mac addresssed

We know that we can use the MAC address to create an interface identifier, e.g. for a link-local IPv6 address which should be unique in the Network.

The image shows the way to do this:

Create interface identifier from MAC address

My questions are:

  • How can I create an IPv6 address from a MAC using awk or sed?
  • OR is there any command that gives me the link-local IPv6 address for a specific MAC (something like that createIPv6 myMAC)?

Best Answer

If you want to create a whole IPv6 address from a MAC (and a given prefix), you could use the excellent ipv6calc tool by Peter Bieringer.

The following command creates a link-local IPv6 address (fe80:: prefix) from a MAC address:

$ ipv6calc --action prefixmac2ipv6 --in prefix+mac --out ipv6addr fe80:: 00:21:5b:f7:25:1b
fe80::221:5bff:fef7:251b

You can leave most of the options away and let the command guess what to do:

$ ipv6calc --in prefix+mac fe80:: 00:21:5b:f7:25:1b
No action type specified, try autodetection...found type: prefixmac2ipv6
fe80::221:5bff:fef7:251b

For Debian distros, ipv6calc is in the main repository.

Related Question