Disable IPv6 on Linux

Followed the common advice from the Internet to disable IPv6 by adding the following to /etc/sysctl.conf:

# disable IPv6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

However, according to ip addr show, there were still 9 inet6 addresses for interfaces like eth0 and wlan0:

ip addr show | grep -c inet6
9

Indeed, according to sysctl output, while net.ipv6.conf.all.disable_ipv6 and net.ipv6.conf.default.disable_ipv6 are set, interfaces not explicitly mentioned still don't have IPv6 disabled:

sudo sysctl -a | grep disable_ipv6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.eth0.disable_ipv6 = 0
net.ipv6.conf.lo.disable_ipv6 = 1
net.ipv6.conf.wlan0.disable_ipv6 = 0

Used the following to add disable ipv6 directives for all the interfaces on the system (sudo -s first):

sysctl -a | 
  grep disable_ipv6 | 
  sed 's/0$/1/' |
  tee -a /etc/sysctl.conf

Enable:

sysctl -p

After this, ip addr show no longer showed any inet6 addresses:

ip addr show | grep -c inet6
0

Leave a comment

NOTE: Enclose quotes in <blockquote></blockquote>. Enclose code in <pre lang="LANG"></pre> (where LANG is one of these).