Read and write IPv6 addresses correctly
Task
Compress, expand and classify a set of IPv6 addresses, then generate a link- local address from a MAC using EUI-64. The notation rules are examinable in their own right, and a compression mistake makes every later answer wrong.
Steps
- Compress these fully, applying both rules: drop leading zeros in each group, and replace one run of all-zero groups with
::. - 2001:0db8:0000:0000:0000:ff00:0042:8329
- fe80:0000:0000:0000:0204:61ff:fe9d:f156
- 2001:0db8:0000:0001:0000:0000:0000:0001
- That third one is the trap. Two separate zero runs exist and only the longer may be replaced. Write down which run you compressed and why.
- Expand these back to full form:
::1,fe80::1,2001:db8::8a2e:370:7334. - Classify each by prefix: global unicast (2000::/3), link-local (fe80::/10), unique local (fc00::/7), multicast (ff00::/8), loopback (::1).
- Derive the EUI-64 interface identifier for MAC
00:1a:2b:3c:4d:5e: split it in half, insertfffein the middle, and flip the seventh bit of the first octet. State the resulting link-local address.
Verify
python3 -c "
import ipaddress
for a in ('2001:0db8:0000:0000:0000:ff00:0042:8329','fe80:0000:0000:0000:0204:61ff:fe9d:f156','2001:0db8:0000:0001:0000:0000:0000:0001','::1','fe80::1','2001:db8::8a2e:370:7334'):
i = ipaddress.ip_address(a)
kind = ('loopback' if i.is_loopback else 'link-local' if i.is_link_local
else 'multicast' if i.is_multicast else 'unique local' if i.is_private else 'global unicast')
print(f'{i.compressed:<28}{i.exploded:<42}{kind}')
mac = '00:1a:2b:3c:4d:5e'.split(':')
b = int(mac[0],16) ^ 0x02
eui = f'{b:02x}{mac[1]}:{mac[2]}ff:fe{mac[3]}:{mac[4]}{mac[5]}'
print('EUI-64 link-local: fe80::' + eui)
"
Six addresses, each shown compressed and expanded, plus the EUI-64 result. The third address must compress to 2001:db8:0:1::1 — if yours has the :: in the first zero run, you replaced the shorter one.
Notes
The two rules that catch people out: :: may appear only once in an address, and when two zero runs are equal in length the convention is to compress the leftmost. Everything else is leading-zero suppression, which is always safe.
EUI-64 is worth doing by hand once because of that flipped bit. The seventh bit is the universal/local flag, and inverting it is what turns a globally unique MAC-derived identifier into one marked as locally assigned. Privacy extensions mean most modern hosts do not use EUI-64 at all — but the exam still asks.