Disable IPv6 on Linux: 3 Proven Methods and Costly Mistakes

To disable IPv6 on Linux there are two different switches: the disable_ipv6 sysctls, which remove IPv6 addresses from interfaces while the system runs, and the ipv6.disable=1 kernel boot option, which turns IPv6 off before anything starts. They do not have the same effect, and most guides also get the details of the sysctl method wrong (it needs no reboot, and on current Debian there is no /etc/sysctl.conf to edit). I tested the sysctl method on a Debian 13 VM, including what still listens on IPv6 afterwards, and used the kernel documentation for the boot option.

Disable IPv6 on Linux with sysctl on Debian 13: interfaces lose their addresses, ::1 cannot be used, sshd still listens on [::]
Real lab output: what disabling IPv6 with sysctl does and does not change.

Before you disable IPv6

Before you disable IPv6, record the current state. The VM started with IPv6 on, like any default install:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 state UNKNOWN qlen 1000
    inet6 ::1/128 scope host noprefixroute
       valid_lft forever preferred_lft forever
2: ens4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000
    inet6 fec0::5054:ff:fe12:3456/64 scope site dynamic mngtmpaddr noprefixroute
       valid_lft 86391sec preferred_lft 14391sec
    inet6 fe80::5054:ff:fe12:3456/64 scope link proto kernel_ll
       valid_lft forever preferred_lft forever

Write down what you see here, especially a global address and a default IPv6 route (this VM had default ... via fe80::2 dev ens4 proto ra). If your network gives you IPv6, some services may already reach the internet over it, and turning it off changes how they connect.

Method 1: disable IPv6 with sysctl, right now

To disable IPv6 for the running system, one command was enough:

# sysctl -w net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.all.disable_ipv6 = 1

# sysctl net.ipv6.conf.lo.disable_ipv6 net.ipv6.conf.ens4.disable_ipv6; ip -6 addr show | grep -c inet6
net.ipv6.conf.lo.disable_ipv6 = 1
net.ipv6.conf.ens4.disable_ipv6 = 1
0

Setting all also switched every existing interface, including loopback, and left zero IPv6 addresses. That matches the kernel's ip-sysctl documentation: changing all/disable_ipv6 "is same as changing conf/default/disable_ipv6 setting and also all per-interface disable_ipv6 settings to the same value". A dummy interface created afterwards also came up with disable_ipv6 = 1 and no address. The old advice to set all, default and lo separately is harmless, but on a current kernel all covers them.

The same page warns that reading all/disable_ipv6 "does not have any particular meaning", because a single interface can be switched back on later. To check, look at the addresses (ip -6 addr), not at that one value.

What breaks after you disable IPv6

When you disable IPv6 this way, anything that uses the IPv6 loopback address ::1 stops working:

# ping -6 -c1 -W1 ::1 2>&1 | tail -1
ping: connect: Cannot assign requested address

OSError: [Errno 99] Cannot assign requested address

The second line is a Python program trying to bind to ::1. Services configured to listen on ::1 or on [::1]:port fail the same way, so check your configs for it before you change anything. Names were less of a problem than you might expect: /etc/hosts still mapped localhost to both 127.0.0.1 and ::1, and curl http://localhost:8000/ still worked, answering 200 via 127.0.0.1.

What does not change: sockets on [::]

Here is the part most guides miss. Binding to the IPv6 wildcard address still worked (bound to :: in the test), and sshd, started before the change, kept both listeners:

# ss -ltn | grep ':22 '
LISTEN 0      128          0.0.0.0:22        0.0.0.0:*
LISTEN 0      128             [::]:22           [::]:*   

With no IPv6 addresses nothing can reach that listener over IPv6, so it is harmless, but it surprises people who check ss to confirm IPv6 is "off". The sysctl method removes addresses; the IPv6 code in the kernel keeps running.

Method 2: make it persistent with sysctl.d

On Debian 13 there is no /etc/sysctl.conf:

ls: cannot access '/etc/sysctl.conf': No such file or directory
/etc/sysctl.d/:
total 4
-rw-r--r-- 1 root root 269 Jul 30  2025 README.sysctl

To disable IPv6 permanently, put the settings in a file of their own, /etc/sysctl.d/90-disable-ipv6.conf:

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

It applies immediately, without the reboot the old post said you need:

# sysctl --system 2>&1 | grep -E 'Applying /etc|disable_ipv6'
* Applying /etc/sysctl.d/90-disable-ipv6.conf ...
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

At boot the same files are applied by the systemd-sysctl service; restarting it in the lab left the value at 1. Files in /etc/sysctl.d/ are described in the sysctl.d manual. To undo, delete the file and set the values back to 0 (or reboot).

Method 3: the kernel boot option

I did not reboot the lab VM with it, so this part comes from the kernel IPv6 documentation. The disable parameter of the ipv6 module, set as ipv6.disable=1 on the kernel command line, means "No IPv6 addresses will be added to interfaces, and it will not be possible to open an IPv6 socket. A reboot is required to enable IPv6." So unlike the sysctl, it also stops programs from opening the [::] listener seen above, and some programs that expect IPv6 sockets may then fail to start. On Debian you add it to GRUB_CMDLINE_LINUX in /etc/default/grub and run update-grub; the current command line is in /proc/cmdline.

Disable IPv6 on Linux: which method to use

The three methods are not interchangeable. Choose by what you want to stop: addresses, or the whole IPv6 stack. And plan the way back before you start, because on a remote server a mistake in network settings can lock you out.

  • Troubleshooting a network problem: sysctl -w net.ipv6.conf.all.disable_ipv6=1, then set it back to 0.
  • Keeping it off: a file in /etc/sysctl.d/ plus sysctl --system.
  • No IPv6 sockets at all: ipv6.disable=1 at boot, after checking that your services cope.
  • Before you disable IPv6 with any of them: search configs for ::1 and [::], and keep a console or out-of-band way into the server.

When IPv6 seems to slow a connection down, check the IPv6 route and DNS first; fixing a broken route keeps the network ready for IPv6-only services. For other sysctl changes and how they load, see Linux performance tuning, and for checking what sshd listens on, how to enable SSH on Ubuntu.

Comments

Popular posts from this blog

How to Play Minecraft Bedrock Edition on Linux: A Comprehensive Guide for Tech Professionals

Linux desktop frozen? My 5 go-to tricks to try - before forcing a hard reboot

The Ultimate Guide: How to Set Up DXVK in Wine on Linux for Enhanced Gaming Performance