First steps with IPv6 – link-local

By default in Linux, in the new distributions, the IPv6 protocol is already activated and, therefore, already in the subnet where the machine is located and it can communicate with others devices using its link-local address. To find out the IPv6 address, use the ifconfig command or the ip command with the following options:

# ip -6 a l dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qlen 1000
inet6 fe80::bc6c:91ff:feb7:be0a/64 scope link
valid_lft forever preferred_lft forever

# ip -6 addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qlen 1000
inet6 fe80::bc6c:91ff:feb7:be0a/64 scope link
valid_lft forever preferred_lft forever

We can see that the address is of the link-local type, using the network prefix fe80. If we have several machines, we can communicate with each other with the ping6 command, but when executing the command, it is necessary to indicate the interface where the ping has to be made. This is because all the interfaces have a link-local address, therefore they have the same prefix and there is no way of knowing which one will be available in one or another interface. In IPv4 the ARP tables were in charge of this, but in IPv6, the concept of ARP does not exist. Therefore, to perform the ping, we use the following command:

# ping6 -I eth0 fe80::ac3e:7bff:fe33:5fb0
PING fe80::ac3e:7bff:fe33:5fb0(fe80::ac3e:7bff:fe33:5fb0) from fe80::bc6c:91ff:feb7:be0a eth0: 56 data bytes
64 bytes from fe80::ac3e:7bff:fe33:5fb0: icmp_seq=1 ttl=64 time=0.966 ms
64 bytes from fe80::ac3e:7bff:fe33:5fb0: icmp_seq=2 ttl=64 time=0.294 ms
^C
--- fe80::ac3e:7bff:fe33:5fb0 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.294/0.630/0.966/0.336 ms

This address can already be used as any IPv4 address, so if a web server is running and has a service with IPv6 support, you can establish the connection through this IP address.

In the following example, we can see how to resolve IP addresses from the https://www.python.org/ domain with IPv4 and IPv6 formats.

You can find the following code in the getaddrinfoIPv4_IPv6.py file:

!/usr/bin/env python3

import socket

def getaddrinfoIPv4(host, port=80, family=0, type=0, proto=0, flags=0):
return socket.getaddrinfo(host=host, port=port,
family=socket.AF_INET, type=type, proto=proto, flags=flags)

def getaddrinfoIPv6(host, port=80, family=0, type=0, proto=0, flags=0):
return socket.getaddrinfo(host=host, port=port,
family=socket.AF_INET6, type=type, proto=proto, flags=flags)


print(getaddrinfoIPv4("www.python.org"))

print(getaddrinfoIPv6("www.python.org"))

This is the output of the previous script where we can obtain IP addresses in the IPv4 and IPv6 formats:

[(<AddressFamily.AF_INET: 2>, 0, 0, '', ('151.101.120.223', 80))]
[(<AddressFamily.AF_INET6: 23>, 0, 0, '', ('2a04:4e42:1d::223', 80, 0, 0))]
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset