Out of the box IPv6 on a Raspberry Pi

 

Out of the box IPv6 on a Raspberry Pi

Following the installation of fresh copy of Raspian on a Raspberry Pi. I wanted to get IPv6 working correctly to allow the use of a range of different IPv6 addresses for different web server applications.

On initial boot only a local link address is setup on the main network interface (eth0 in this case) In order to get the install to get an address from the router it needs to be able to accept router advertisments.

Unfortunately, net.ipv6.conf.eth0.accept_ra is set to zero. This is the default setting.

So set it to one ...

sudo sysctl net.ipv6.conf.eth0.accept_ra=1

... and then a global address is allocated to the machine. Well, that's not entirely true. It does work but you may have to wait for up to 20 minutes. I'm not clear on why it takes so long sometimes.

You can check to see if a global address has been allocated like this ...

ip -6 a
  inet6 2001:8b0:..:..:..:..:..:../64 scope global dynamic mngtmpaddr 
     valid_lft 4294966685sec preferred_lft 4294966685sec

You can further check your connection to the outside world is working correctly via ...

ping6 google.com

That is all very well and dandy but it's not automatic and so would need to be done after each boot. So the next step is to include it in the boot sequence.

This site provided the answers IPv6 Networking and DAD

The solution is to add a script to the IPv6 interface configuration ...

#!/bin/bash
# script /etc/network/if-up.d/ipv6-post-config
# Start up IPv6 and add addresses

[ "$IFACE" = '--all' ] || exit 0;
[ "$MODE"  = 'start' ] || exit 0;

echo "IPv6 post-up accept router adverts";

sleep 30;

sysctl net.ipv6.conf.eth0.accept_ra

sysctl net.ipv6.conf.eth0.accept_ra=1

echo "IPv6 post-up wait for network to wake up (potentially a very long time)";

while [ $(ip -6 addr show eth0 | grep -c 2001) -eq 0 ]; do
  echo "IPv6 post-up wait for network wake up";
  sleep 10;
done

echo "IPv6 post-up wait for address to finish DAD";

while [ $(ip addr show eth0 | grep -c tentative) -ne 0 ]; do
  echo "IPv6 post-up tentative to global";
  sleep 10;
done

echo "IPv6 post-up network check";

ping6 -c 1 google.com
ip -6 a

echo "IPv6 post-up network now fully available";

This script allows the reception of router advertisments, waits for the IPv6 network to startup and then waits until the address has completed DAD.

#IPv6 #Raspberry Pi