On Fri, Apr 20, 2012 at 6:43 AM, Joost Roeleveld <jo...@antarean.org> wrote:
> On Thursday, April 19, 2012 04:12:35 PM Michael Mol wrote:
>> On Thu, Apr 19, 2012 at 4:01 PM, Alex Schuster <wo...@wonkology.org> wrote:
>> > Michael Mol writes:
>> >> On Thu, Apr 19, 2012 at 3:40 PM, Alex Schuster <wo...@wonkology.org>
>> >>
>> >> wrote:
>> >> > New output:
>> >> > eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
>> >> >        inet 192.168.2.42  netmask 255.255.255.0  broadcast


>> >> > 192.168.2.255 inet6 fe80::be5f:f4ff:fe19:ad18  prefixlen 64  scopeid
>> >> > 0x20<link>


>> >> >
>> >> >        ether bc:5f:f4:19:ad:18  txqueuelen 1000  (Ethernet)

[snip]

>> Incidentally, you can derive it from your IPv6 LL address, but that's
>> a bit of a roundabout way, and may not work if you've disabled IPv6.
>
> How do you derive it?
> I don't see the mac-address in the inet6 address.

https://en.wikipedia.org/wiki/IPv6_address#Modified_EUI-64

The inet6 address listed is

  fe80::be5f:f4ff:fe19:ad18

and your MAC is

  bc:5f:f4:19:ad:18

First, let's chop off the fe80:: portion. The fe80 means it's a
link-local address, and the :: means that that space in the address is
greedily (think regex) filled with 0s. That leaves us with

  be5f:f4ff:fe19:ad18

Right in the middle of that, you see ff:fe. That part is added by
IPv6's autoconfiguration logic. Yank that out, and you're left with

  be5f:f419:ad18

IPv6 addresses put the : between every group of 16 bits. The
representation of your MAC address has the : between every group of 8
bits. So we just insert more : characters where they're missing.

  be:5f:f4:19:ad:18

Which is your MAC.

This autoconfiguration logic is used all over the place as part of
Stateless Link Automatic Address Configuration, or SLAAC, and it means
you don't need DHCP for many environments.

As an exercise example, here are the numbers on the latop I'm using right now:

MAC: e0:69:95:c5:29:5f
IPv6 link-local address: fe80::4eed:deff:fe93:63a0
IPv6 global address: 2001:470:c5b9:beef:4eed:deff:fe93:63a0

The breakdown of my global-scope address is slightly trickier, because
there aren't a bunch of 0s for a :: to consume. My IPv6 ISP gave me a
prefix of 2001:470:c5b9::/48, I set up my wireless network to have a
prefix of 2001:470:c5b9:beef::/64. What's left, 4eed:deff:fe93:63ao,
is common between the link-local and global-scope addresses.

And you should now know enough to derive my MAC address from either my
link-local address or my global-scope address.

Note that this won't necessarily work on all platforms. If you have
IPv6 privacy extensions enabled, a conforming IP stack (including on
Linux) should still work this way...except Windows uses a *randomized
MAC* as a basis. Also, if you're on a network which uses DHCPv6, I
can't guarantee what you'd get for ULA or global-scope addresses
(depends on your network admin's choices), but your link-local address
should still look the same.

-- 
:wq

Reply via email to