Ben's Blog

all out geekery, I.T. ben February 16, 2012

MAC address to IPv6 link-local address online converter

The converter

It can also be addressed directly via:
https://ben.akrin.com/ipv6_mac_address_to_link_local_converter/?mode=api&mac=52:74:f2:b1:a8:7f
for all your API needs.

The math

Link-local IPv6 addresses are used as part of the IPv6 network auto-configuration process. Instead of getting an address via DHCP, a NIC will hop on the network with a link-local IPv6 address and with this will have to ability to do further configuration automatically (soliciting neighbors, router, et cetera).

This link-local IPv6 is infered from the NIC’s mac address.

A mac address is 48 bits, an IPv6 address is 128 bits. Here’s the conversion process step by step:

  1. take the mac address: for example 52:74:f2:b1:a8:7f
  2. throw ff:fe in the middle: 52:74:f2:ff:fe:b1:a8:7f
  3. reformat to IPv6 notation 5274:f2ff:feb1:a87f
  4. convert the first octet from hexadecimal to binary: 52 -> 01010010
  5. invert the bit at index 6 (counting from 0): 01010010 -> 01010000
  6. convert octet back to hexadecimal: 01010000 -> 50
  7. replace first octet with newly calculated one: 5074:f2ff:feb1:a87f
  8. prepend the link-local prefix: fe80::5074:f2ff:feb1:a87f
  9. done!

Going the other way

A converter to do the same operation in reverse is available here.

Comments

There have been a few interesting comments on this post, I encourage you to read them if you want to learn more about this mechanism. Specifically:

  • Why in the world would you flip that bit?
  • Bitnukl sharing a Windows trick

Recent Comments

  1. Ben says:
    February 18, 2013 at 9:48 am

    Reverse the instructions obviously.

    Reply
  2. Channa says:
    March 3, 2013 at 6:21 am

    Can you also explain why one has to invert the bit in step 5 above? What is its rationale?

    Reply
    • Ben says:
      March 3, 2013 at 7:23 pm

      Sure, this isn’t actually a construct of the MAC to link-local IPv6 mechanism per se. Based on RFC 4291 section 2.5.6, a link-local IPv6 address is just “fe80” followed by 54 null bits followed by the Interface ID. The trick here is that the “Interface ID” is not the same thing as a mac address, I think it’s meant to be the new mac address but I have yet to see one in the wild. As a result we also need to go from mac address to interface ID by flipping the bit in step 5 and adding ff:fe in the middle.

      More info here: http://www.tcpipguide.com/free/t_IPv6InterfaceIdentifiersandPhysicalAddressMapping-2.htm

      If I see an interface ID anywhere I’ll have to update this guide a bit 🙂

      I hope this helps.

      Reply
    • Clint says:
      July 14, 2013 at 7:26 am

      Bit 6 in the MAC address “global/local” bit. When set to 1 it indicates that the MAC address was set manually by an administrator, rather than burned into the network card following the normal rules for vendor identification.

      Since people who wish to manually set an IPV6 address would likely use many zero’s, something like FE80::24 (FE80:0000:0000:0000:0000:0000:0000:0020), the conversion was designed that such manual address would indicate that it was generated from a locally administered mac address rather than a real MAC.

      Reply
      • Elgs says:
        October 30, 2015 at 11:25 am

        When set to 1 it indicates that the MAC address was set manually by an administrator, rather than burned into the network card…

        and

        FE80::24 (FE80:0000:0000:0000:0000:0000:0000:0020), the conversion was designed that such manual address would indicate that it was generated from a locally administered mac address rather than a real MAC.

        seem to be conflict with each other.

        Reply
      • Yo THanks says:
        February 2, 2023 at 2:31 pm

        Old post but its finally the path to why this bit is swapped.
        It is actually not the 6th bit of the MACadress first octet but the 2nd (b1) which distinguishes universal (0) and locally (1) administered addressing.
        It’s kinda neat. Every LLA that is generated from a MAC that was universal administered (set by manufacturer) has always a by 2 reduced first octet compared to the first one of the MAC.

        Reply
  3. angvish says:
    March 18, 2013 at 6:55 am

    what does prepend the link-local prefix mean ?

    Reply
  4. John says:
    April 4, 2013 at 7:48 pm

    Thank you for providing this utility. I have found it be useful on several occasions. Would you please consider modifying to code so that both UPPER and lower case letters are accepted?

    Reply
    • Ben says:
      April 5, 2013 at 3:15 am

      Sure thing & done.

      I’ve only hacked it so everything is converted to lowercase but the end result is that both UPPER & lower cases are accepted.

      Reply
      • mike says:
        November 17, 2016 at 7:47 pm

        I was looking at the example you gave above. It says 52, but the binary adds up to 82. I could be wrong. But 01010010, 64 + 16 + 2 = 82, then inverted would equal 80. I am relatively new to this and could be wrong. But lets say it was 52, the binary would be 00110100, 32 + 16 + 4, then inverted would be 00110110, 32 + 16 + 4 + 2 would = 54. Am I right or am I still not understanding this stuff?

        Reply
        • ben says:
          November 18, 2016 at 3:14 am

          I think you’re confusing hexadecimal with decimal. At no point in the operation are we dealing with decimal numbers.

          We go from hexadecimal to binary and then back from binary to hexadecimal.

          You are right that (bin)01010000 is (dec)80, but we’re not interested in (dec), what we want is (hex)50.

          Mac addresses & IPv6 addresses are hex based, IPv4 is decimal so there’s that to add confusion 🙂

          I hope this helps.

          Reply
  5. Jay says:
    April 10, 2013 at 8:24 pm

    Just wanted to say thanks for posting this online!

    Reply
    • Ben says:
      April 11, 2013 at 8:47 am

      It’s great to know people use it, thanks!

      Reply
  6. Frank says:
    May 2, 2013 at 8:25 pm

    I enter my MAC address, but the calculated Link Local does not match what IPCONFIG shows my Link Local to be. It isn’t even close. The calculator follows what I have learned about creating the LL from the MAC, but what IPCONFIG shows on my machine is not even close to my MAC. Yes, I am looking at the entry for Link-local IPv6 Address and the starting block is FE80. Please explain if you will. TIA.

    Reply
    • Ben says:
      May 3, 2013 at 8:50 am

      Could you tell me what your MAC address is and what ipconfig gives you for a Link-Local address?

      Feel free to email them at temp@akrin.com if you have privacy concerns.

      I’m not a Windows guy but I think it uses some sort of tunneling adapter for IPv6, could it be that you’re looking at the MAC of your NIC and the LL address of that adapter? I’ll see if I can get my hands on a Windows box to see what things look like on this side of things.

      Reply
      • James says:
        April 7, 2014 at 5:20 am

        Hi Ben,
        Could you explain what was the problem for Frank?
        Thanks!

        Reply
        • Ben says:
          April 7, 2014 at 8:53 am

          Frank never followed up unfortunately, but Bitnukl answered and gives a cool trick bellow:

          http://ben.akrin.com/?p=1347#comment-84

          Reply
  7. bitnukl says:
    August 21, 2013 at 10:20 am

    Since Win Vista Windows uses random ipv6 link local addresses.
    You can force it to use EUI-64-based interface IDs with the command:
    netsh interface ipv6 set global randomizeidentifiers=disabled

    Reply
  8. Steve Hannah says:
    September 23, 2013 at 10:02 am

    Either I don’t follow the process correctly or the math is wrong for your conversion from a MAC address to an IPv6 address. Under “The Math,” you convert 52 to 01010010. I got 00110100. Please clarify. Thanks.

    Reply
    • Ben says:
      September 23, 2013 at 4:00 pm

      From Hex to Bin 🙂

      Not from Dec to Bin.

      Reply
  9. token1 says:
    September 27, 2013 at 12:31 am

    i think you should call it the ‘7th’ bit , when you call it ‘6th’ — all kinds of confusion happens. Just saying that everyone else identifies that bit as 7th , also it is more logical to start your counting from one rather than zero. nice explanation though — worked for me.

    Reply
    • Ben says:
      September 27, 2013 at 10:00 am

      Well sure it’s the 7th bit, but it’s “the bit at index 6 (counting from 0)” for anything you’ll script because you’ll be dealing with an array. There is no such thing as “more logical to start your counting from one rather than zero” only conventions & standards. More intuitive maybe but not when you’re dealing with arrays. “Everybody is doing it” is not a valid argument.

      All in all as long as it’s labeled properly let’s worry about something else maybe?

      Reply
      • Cathi says:
        November 23, 2014 at 7:59 pm

        I just want to mention that as I’m still studying things, I was very glad for the comment about 6th/7th bit because I was starting to get very confused about how that worked, and actually visited the comments wondering if it was a typo. After reading the suggestion and reply above my post, I understand and was relieved at the clarification.

        Thanks for the great tool, too!

        Reply
      • Jean says:
        July 5, 2016 at 8:42 am

        Actually you are both wrong 😉 The bit to flip is bit 1. When counting bits you typically start from 0 (Ben is right) but you also start counting from the least significant bit.

        It’s all about conventions, obviously.

        Reply
        • ben says:
          July 8, 2016 at 2:19 pm

          Hah! Thanks for setting the record straight 🙂 I’m surprised this is the most controversial piece of the algorithm.

          Reply
  10. avinash says:
    October 5, 2013 at 3:04 am

    Using the mac address B8:CA:3A:BF:3B:32 construct the link-local address with the
    MAC-to-EUI64 conversion process. Afterwards construct the IPv6 header (just the
    next header, source, and destination addresses) and the ICMPv6 Neighbor Solicitation
    (NS) header message format (type, code, target address). Then construct the IPv6
    header and Neighbor Advertisement (NA) message header (type,code, flags, and
    target address) as if the tentative address is duplicated on another node.

    Reply
  11. Ben says:
    November 27, 2013 at 5:07 pm

    Hey Ben…recent changes appear to have broken this page…it processes the request, but no results are returned, just an empty doc.

    Reply
    • Ben says:
      November 30, 2013 at 9:34 pm

      Thanks for letting me know Ben! A careless recursive chmod was the culprit.

      Reply
  12. shravan says:
    December 6, 2013 at 3:47 am

    how to find scope id in this case.. ? and what is the standard way of representing IPv6 link local address ?
    Is it nessesary to display scope id also if we want to display link local address somewhere ?

    Reply
  13. Raghav says:
    June 4, 2014 at 10:56 pm

    Hello, isn’t the “7nth bit” fliped instead of the “6th bit” while converting a mac address into IP version 6?

    The person who wrote this guide says to flip the 1 that makes “52” into a “0”. I think they are wrong and if not please correct me by telling me why is it the 6th bit?

    The 7nth bit is fliped. So, if in the mac address there is a 1 in the 7nth position of the 8 bits, then the 1 becomes a 0 and if it is a 0 instead of a 1, it becomes a 1 in the 7nth position.

    Also many zero’s equal to :: “Double Coulmn?
    Thanks very much. Im a beginer to subnetting. Correct me if i am wrong. Im doing CCNA1 in cisco.

    Reply
    • Ben says:
      June 5, 2014 at 10:06 am

      From the instructions:
      “5. invert the bit at index 6 (counting from 0)”

      So yes, it’s the 7th bit but bit number 6 counting form 0 which is most likely how you’ll be counting if you script this stuff 🙂

      Many zeros do indeed equal to double column but this is for abbreviation purposes; meaning that fully writing each 0 is legal as well.

      Reply
  14. Sebastian says:
    June 7, 2014 at 4:48 pm

    52 -> 00110100

    6)
    00110100 + 00000010 = 00110110 -> 54
    another example:
    BC -> 10111100 + 00000010 = 10111110 -> BE

    Reply
    • Ben says:
      June 9, 2014 at 8:51 am

      Are you suggesting that my hex2bin is wrong? Cause I’m pretty sure it ain’t.

      Also “+ 00000010” is not the same thing a bit flipping. Care to explain further?

      Reply
  15. martin ck says:
    November 10, 2014 at 4:11 am

    Ben .. Thanks for this … I was wondering if anyone has tried an excel formulae for this and if they would care to share.
    Use this a lot martin

    Reply
    • Ben says:
      November 10, 2014 at 11:22 am

      Not that I’m aware of sorry!

      Reply
  16. oscar says:
    September 5, 2015 at 12:41 am

    Hi I m Oscar anybody please help me to change my phone mac address Microsoft Lumia 640lte

    Reply
  17. Gavin Burke says:
    November 10, 2015 at 12:47 pm

    So I use this tool and I do not get the same result as my Windows machine:

    Physical Address= 0A-00-27-00-00-00
    Link-local IPv6 Address= fe80::485:8161:2716:2a51

    How come?

    Reply
    • ben says:
      November 10, 2015 at 2:39 pm

      Bitnukl explained it in the comments: http://ben.akrin.com/?p=1347#comment-84

      Reply
  18. Dave Russell says:
    February 29, 2016 at 3:26 am

    Hi, nice utility. How about one to convert from IPv6 Address to MAC Address?

    Reply
    • ben says:
      March 4, 2016 at 12:30 am

      Per your suggestion, here it is. I hope this helps.

      Reply
  19. brownjr says:
    March 3, 2016 at 1:03 pm

    you can find more information on the website http://wlan-wifi.com/mac-address

    Reply
  20. Kai says:
    April 1, 2016 at 8:57 pm

    Hey,
    can please put the Skript on github or something like that. I need that for a little project and don’t want to use your api because of reasons. I tried everything in PHP but I’ve failed 🙁

    Reply
    • ben says:
      April 2, 2016 at 12:51 am

      I’d rather not unfortunately, this is code ran on my web server and as a security rule of thumb, I don’t post it online in case there is a security flaw that is evading me. Did you post this with your actual email address? I could send you the meat of the script.

      Reply
  21. Yubraj Sharma says:
    July 25, 2016 at 7:03 am

    What does the “invert the bits at index six” mean?

    Reply
    • ben says:
      July 26, 2016 at 1:31 am

      It means you start counting bits at 0 from left to right, when you’re at number 6 you flip the bit (if it’s a 0 it becomes a 1 and vice versa).

      Reply
  22. Lavan says:
    November 7, 2016 at 4:22 pm

    ipconfig /all

    you will see ‘Physical Address’ = MAC address

    P.S: thanks for your input Ben, way to be a leader :p

    Reply
    • ben says:
      November 7, 2016 at 5:42 pm

      Read the question, the guy wants the mac derived form the link local, not using a local command. So I’m sitting there thinking just reverse the freaking steps, I ain’t doing that for you. Many people don’t want to commit to the slightest amount of work and would much rather have someone else do it for them.

      Hence my response 🙂

      P.S.: read the original question :p

      Reply
      • Ken says:
        September 26, 2018 at 6:51 am

        You are very arrogant and unhelpful Ben. Would have been better had you not responded at all

        Reply
        • ben says:
          September 26, 2018 at 7:06 pm

          You’re welcome 🙂

          Reply
          • Tucker says:
            June 21, 2019 at 11:33 pm

            Thanks for the great and simple web page ben. I use it very often.

  23. jon says:
    March 9, 2018 at 2:29 pm

    should handle “-” in place of “:” in the hardware mac.

    Reply
    • ben says:
      March 9, 2018 at 2:48 pm

      Ok done.

      Reply
  24. John says:
    June 2, 2018 at 6:56 am

    Helped me very much and the questions/answers too.
    Thanks.

    Reply
    • ben says:
      June 4, 2018 at 1:31 pm

      Always nice to get a “thanks” 🙂 Vive la Belgique.

      Reply
  25. Rob says:
    July 7, 2019 at 4:58 am

    When I put in my MAC address the results on the page don’t match what’s in the link local address on my computer.

    Reply
    • ben says:
      July 8, 2019 at 1:51 pm

      Take a look at Bitnukl’s comment: https://ben.akrin.com/?p=1347#comment-89

      It looks like Windows does random link local IPv6 by default these days.

      Reply
  26. Karthik Sriram says:
    January 22, 2022 at 11:38 pm

    Hi Ben, thank you for this useful tool. However, I found my machine (and several others that I have tried) don’t seem to have the link-local address that this tool generates.
    Here’s my example mac address: 00:d8:61:5d:55:ce, generating fe80::2d8:61ff:fe5d:55ce
    And here’s what `ip addr` generates:
    `inet6 fe80::6ac2:6911:27c6:f4cf/64 scope link noprefixroute
    valid_lft forever preferred_lft forever`
    I am not quite sure why. Is this address different from the link local address?
    Thank you for your help.

    Reply
    • ben says:
      January 23, 2022 at 2:15 am

      Hi Karthik,

      if you are on windows, could it be because of this trick shared 9 years ago? => https://ben.akrin.com/?p=1347#comment-89

      Reply
  27. ictus says:
    June 22, 2022 at 2:33 am

    In case someone is looking for this in bash:

    [bash]mac2ipv6() {
    local mac=$1 ; \
    echo $mac | \
    tr ‘-‘ ‘:’ | \
    tr ‘[:upper:]’ ‘[:lower:]’ | \
    awk -F: ‘{printf "fe80::%s%x%s:%sff:fe%s:%s%s\n", substr($1,1,1), xor(strtonum("0x"substr($1,2,1)),2), $2, $3, $4, $5, $6}’
    }[/bash]

    Reply
    • ben says:
      June 22, 2022 at 2:41 am

      Tested and approved, thank you for this :).

      Reply
    • WaterLemons2k says:
      March 31, 2023 at 4:16 am

      If someone gets an error:

      function xor never defined
      function strtonum never defined
      Call to undefined function

      Install gawk will fix this.

      Reply
  28. vicnent says:
    October 15, 2024 at 8:41 am

    Please make it so that the result appears on a single line so that I can double click to select it instead of having ‘resulting IPv6 address:’ being part of the result line.
    (Or better yet have a copy button to copy the results directly.)

    The current workflow consist of double clicking the result, opening nodepad++, pasting the buffer removing the ‘resulting IPv6 address:’ part to keep only the ipv6 address, copy the ipv6 address.

    Reply
    • ben says:
      October 15, 2024 at 5:39 pm

      You could select only the mac address instead of going through Notepad. Agreed though, something quicker is nice and I did add the “copy to clipboard” button. If you are doing anything repetitive, the API version is what you’re after.

      Reply
  29. Pingback: Debian 7 how are IPv6 link local addresses set? – segmentfault
  30. Pingback: Unix/Linux:Networking fundamentals: what IP is assigned a NIC if there is no successful DHCP negotiation? – Unix Questions
  31. Pingback: IPv6 link-local address to MAC address online converter | Ben's blog
  32. Pingback: Ad and tracker blocking – (re)Tired Tech(ie)
  33. Pingback: Is it possible to SSH access a server with a misconfigured subnet? – Blog SatoHost
  34. Pingback: 当我知道另一台机器的ipv4时,确定另一台机器的ipv6地址 – 玩编程
  35. Pingback: Quick guide to IPv6 Unicast addresses – Ramblings of a nut
  36. Pingback: How to setup PostgreSQL on an IPv6 enabled network - Highgo Software Inc.
  37. Pingback: David Z: How to setup PostgreSQL on an IPv6 enabled network – Cloud Data Architect
  38. Pingback: IPv6 Neighbor Discovery/Routing Failing for Kernel 3.10 - Boot Panic
  39. Pingback: IPv6 - How to setup PostgreSQL on an IPv6 enabled network - techbuddies.io

Leave a Comment

Cancel reply

This blog is solar powered

Interactive

  • Handwriting Capture
  • Mandalagaba
  • IPv6 link-local to MAC converter
  • IPv6 MAC to link-local converter
  • Markov Text Generation
  • Markov Word Generation
  • Markov Music Generation
  • Duplogrifier
  • Flood Fill Algorithms
  • Homestead Metrics
  • RGB Playground
  • Web Games

Categories

  • aesthetics111
    • plots54
    • specular holography6
  • Books3
  • I.T.202
    • 3D modeling / printing21
    • AI6
    • all out geekery36
    • electronics27
    • homestead automation6
    • maniacal paranoia25
    • plotters49
    • unix / linux29
    • video games4
    • web development29
    • web games3
  • Lego / Duplo67
  • life in the U.S.42
  • miscellaneous202
  • nature encounters114
  • old vinyls3
  • organs2
  • self sustainability560
    • agriculture105
    • apiculture38
    • apple20
    • building131
    • canning3
    • crochet6
    • foraging6
    • hunting10
    • maple syrup47
    • poultry39
    • preserving2
    • solar power28
    • water23
    • wood84
  • trip to a new life6
Theme by Bloompixel. Proudly Powered by WordPress