Networking Tutorial · Networking Basics · Lesson 6 of 28
IPv6
Why IPv6 exists, how its addresses are written and shortened, and how it is used in cloud networks.
Why IPv6?
IPv4's 4.3 billion addresses ran out: the regional internet registries handed out their last large IPv4 blocks between 2011 and 2019. IPv6 uses 128-bit addresses, about 3.4 × 10^38 of them, so every device can have a globally unique address and NAT is no longer needed for address sharing.
Writing IPv6 addresses
Eight groups of four hexadecimal digits, separated by colons:
2001:0db8:0000:0000:0000:ff00:0042:8329
2001:db8::ff00:42:8329 same address, shortened
Leading zeros in a group can be dropped, and one run of all-zero groups can be replaced with ::.
import ipaddress
ip = ipaddress.ip_address("2001:0db8:0000:0000:0000:ff00:0042:8329")
print("compressed:", ip.compressed)
print("exploded: ", ip.exploded)
print("loopback: ", ipaddress.ip_address("::1").is_loopback)
Output
compressed: 2001:db8::ff00:42:8329 exploded: 2001:0db8:0000:0000:0000:ff00:0042:8329 loopback: True
IPv6 in the cloud
- A typical LAN or cloud subnet is a
/64(18 quintillion addresses). AWS gives a VPC a/56and each subnet a/64. - IPv6 addresses are usually public, so "private" subnets use an egress-only internet gateway (AWS) or firewall rules to allow outbound connections only, instead of NAT.
- Dual-stack networks run IPv4 and IPv6 side by side; DNS
AAAArecords hold IPv6 addresses.
import ipaddress
vpc = ipaddress.ip_network("2001:db8:1200::/56")
subnets = vpc.subnets(new_prefix=64)
print(vpc.num_addresses == 2 ** 72, "- a /56 holds 2**72 addresses")
for _ in range(3):
print("subnet:", next(subnets))
print("a /56 holds", 2 ** (64 - 56), "subnets of /64")
Output
True - a /56 holds 2**72 addresses subnet: 2001:db8:1200::/64 subnet: 2001:db8:1200:1::/64 subnet: 2001:db8:1200:2::/64 a /56 holds 256 subnets of /64
Test yourself
Which is a valid shortened form of 2001:0db8:0000:0000:0000:0000:0000:0001?
2001:db8::12001:db8:12001::db8::12001:db8:0::0::1
Show answer
Answer: 2001:db8::1
Drop leading zeros and replace the single run of zero groups with ::. Using :: twice is ambiguous and invalid.