Disabling IPv6

Last update: 2023-03-26 06:47:41 +0800 +0800
Available translations: 日本語 / 中文(简体) / 中文(繁體)

Disabling IPv6 removes IPv6-only reachability and can break loopback, container, DNS, and application assumptions. Diagnose address selection and connectivity before treating it as the remedy for a timeout.

Diagnose Address Selection First #

Name resolution can return both IPv6 and IPv4 addresses. A dual-stack client uses address-selection and connection-fallback logic; a failure can instead indicate DNS, a route, firewall policy, path MTU discovery, or a service bound only to IPv4.

sh
getent ahosts localhost
ip -6 address show
ip -6 route show
curl -6 --connect-timeout 5 https://example.com/

Test the target and the service binding. A listener on 127.0.0.1 is not reachable through ::1; configure the intended IPv4 and IPv6 listeners explicitly. Repairing the faulty path preserves dual-stack operation.

Disable IPv6 at Boot #

The kernel command-line parameter ipv6.disable=1 disables IPv6 functionality from boot. It prevents IPv6 addresses and IPv6 sockets; re-enabling it requires a reboot. Add it through the bootloader’s persistent configuration, regenerate the deployed boot entry using the distribution’s documented command, and reboot.

A GRUB configuration can contain:

properties
GRUB_CMDLINE_LINUX="ipv6.disable=1"

On Arch systems, regenerate the configuration after editing:

sh
sudo grub-mkconfig -o /boot/grub/grub.cfg

The installed path and bootloader differ across systems. Verify /proc/cmdline after reboot rather than assuming an edited file was used. When the bootloader uses an initramfs or Unified Kernel Image, update its command line through the corresponding build process as well.

Control IPv6 through sysctl #

The disable_ipv6 sysctl disables addresses and IPv6 operation for an interface while the IPv6 kernel support remains loaded. Store persistent defaults in a sysctl configuration file:

conf
# /etc/sysctl.d/99-disable-ipv6.conf
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1

Apply the change with sudo sysctl --system, or reboot. all affects existing interfaces; default supplies the value for interfaces created later. Control a specific interface with net.ipv6.conf.<interface>.disable_ipv6, for example:

sh
sudo sysctl -w net.ipv6.conf.wlan0.disable_ipv6=1

Network managers, containers, and VPN software can create interfaces after boot, which is why both settings matter. A later sysctl write can re-enable IPv6 under this method.

Verify the Effective State and Consequences #

sh
cat /proc/cmdline
cat /proc/sys/net/ipv6/conf/all/disable_ipv6
ip -6 address show
ss -lnt6

With ipv6.disable=1, the IPv6 proc hierarchy may be absent and IPv6 sockets cannot be opened. With the sysctl method, a value of 1 confirms the selected interface behavior. Test the applications that matter after changing either setting: localhost resolution, services bound to ::1, IPv6-only DNS records, container networks, VPNs, and monitoring agents can all depend on IPv6 support.

Comments

Read or comment on GitHub (sign-in required to comment)