How to disable IPv6 on Raspberry Raspbian

An easy guide on how to disable IPv6 on Raspbian that anyone can accomplish in just a few minutes. Tested on Raspbian Jessie.

Reason for disabling

Avoiding IPv6 leak when using IPv4-only VPN

In the presence of both IPv4 and IPv6, the priority is to use the IPv6 path first before falling back to IPv4. This can be a problem when used in conjunction with VPN where most VPN providers are still providing IPv4 service exclusively. An IPv6-enabled machine will bypass the VPN.

Need implicit firewall with NAT

IPv6 no longer use NAT; all devices are Internet routable. The implicit protection offered by NAT in IPv4 is now gone. This means the overall network security setup needs a rethink prior to introducing IPv6.

Disabling IPv6 at router is an easy way to turn this off for all devices but you may want to selectively enable on some.

Disabling IPv6

Firstly, check for presence of IPv6 using ifconfig. You should be seeing a few lines containing inet6 addr: ....

To disable, edit a file: sudo nano /etc/sysctl.conf

Add the following line:

net.ipv6.conf.all.disable_ipv6 = 1

For the change to take effect without rebooting:

sudo sysctl -p

Verify that IPv6 address does not show up in ifconfig.

Re-enabling IPv6

If you wish to re-enable, change the value in the setting above from 1 to 0 then execute the following two lines:

sudo sysctl -p
sudo ifconfig eth0 down && sudo ifconfig eth0 up

If you are doing this over SSH, the current session will of course be cut off. You should be able to reconnect in just a few seconds.

Support Me

If this post helped you, would you buy me a cup of tea/coffee?