for all your API needs.
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:
- take the mac address: for example 52:74:f2:b1:a8:7f
- throw ff:fe in the middle: 52:74:f2:ff:fe:b1:a8:7f
- reformat to IPv6 notation 5274:f2ff:feb1:a87f
- convert the first octet from hexadecimal to binary: 52 -> 01010010
- invert the bit at index 6 (counting from 0): 01010010 -> 01010000
- convert octet back to hexadecimal: 01010000 -> 50
- replace first octet with newly calculated one: 5074:f2ff:feb1:a87f
- prepend the link-local prefix: fe80::5074:f2ff:feb1:a87f
Going the other way
A converter to do the same operation in reverse is available here.
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:
71 Replies to “MAC address to IPv6 link-local address online converter”
In case someone is looking for this in bash:
Tested and approved, thank you for this :).
If someone gets an error:
function xor never defined
function strtonum never defined
Call to undefined function
gawkwill fix this.
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.
if you are on windows, could it be because of this trick shared 9 years ago? => https://ben.akrin.com/?p=1347#comment-89
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.
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.
Helped me very much and the questions/answers too.
Always nice to get a “thanks” 🙂 Vive la Belgique.
should handle “-” in place of “:” in the hardware mac.
you will see ‘Physical Address’ = MAC address
P.S: thanks for your input Ben, way to be a leader :p
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
You are very arrogant and unhelpful Ben. Would have been better had you not responded at all
You’re welcome 🙂
Thanks for the great and simple web page ben. I use it very often.
What does the “invert the bits at index six” mean?
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).
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 🙁
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.
you can find more information on the website http://wlan-wifi.com/mac-address
Hi, nice utility. How about one to convert from IPv6 Address to MAC Address?
Per your suggestion, here it is. I hope this helps.
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
Bitnukl explained it in the comments: http://ben.akrin.com/?p=1347#comment-84
Hi I m Oscar anybody please help me to change my phone mac address Microsoft Lumia 640lte
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
Not that I’m aware of sorry!
52 -> 00110100
00110100 + 00000010 = 00110110 -> 54
BC -> 10111100 + 00000010 = 10111110 -> BE
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?
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.
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.
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 ?
Hey Ben…recent changes appear to have broken this page…it processes the request, but no results are returned, just an empty doc.
Thanks for letting me know Ben! A careless recursive chmod was the culprit.
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.
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.
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?
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!
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.
Hah! Thanks for setting the record straight 🙂 I’m surprised this is the most controversial piece of the algorithm.
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.
From Hex to Bin 🙂
Not from Dec to Bin.
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
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.
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 email@example.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.
Could you explain what was the problem for Frank?
Frank never followed up unfortunately, but Bitnukl answered and gives a cool trick bellow:
Just wanted to say thanks for posting this online!
It’s great to know people use it, thanks!
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?
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.
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?
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.
what does prepend the link-local prefix mean ?
Can you also explain why one has to invert the bit in step 5 above? What is its rationale?
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.
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.
When set to 1 it indicates that the MAC address was set manually by an administrator, rather than burned into the network card…
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.
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.
Reverse the instructions obviously.