How to Disable IPv6 in Linux

A photograph of a red sign with the label "Internet."

IPv6 is one of the biggest developments in computer networking. It provided a larger address space for the Internet along with improvements in routing and global addressability. That said, IPv6 adoption is still in its infancy and running IPv6-capable computers on IPv4-only networks can result in connection issues. This article will show you how you can disable IPv6 on your Linux machine and use it in an IPv4-only network.

How to Verify IPv6 Status

The quickest way to check for your machine’s IPv6 status is by running the ip addr command on a terminal. This is a utility that will print all the available network interfaces that are running the IPv6 network stack:

ip -6 addr

You can also check your computer’s kernel binary if it’s running the kernel module for IPv6. The following command will print the “/proc” file path for the IPv6 module if the kernel is actively loading it:

ls /proc/net/if_inet6

How to Disable IPv6 in Linux

For the most part, permanently disabling the IPv6 protocol on Linux will require you to add a new argument to your bootloader. To do this, open your GRUB configuration file with your favorite text editor:

sudo nano /etc/default/grub

Press Ctrl + W, then search for “GRUB_CMDLINE_LINUX_DEFAULT.”

A terminal highlighting the Grub argument line.

Write ipv6.disable=1 to the end of the variable’s value.

A terminal showing the IPv6 argument for Grub.

Save (Ctrl + O) and exit (Ctrl + X) the text editor.

Reload your bootloader’s configuration file:

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

Reboot your system, then run ls /proc/net/if_inet6 to check if you’ve successfully disable IPv6 on your machine.

Good to know: learn how bootloaders work by looking at a comparison between Grub and Systemd-boot.

Disable IPv6 on Red Hat-based Systems

Aside from directly configuring your computer’s bootloader, you can also disable IPv6 on the userland level. This is helpful if you only want to disable IPv6 on certain network interfaces.

To disable IPv6 on Red Hat-based distros, open a new terminal session then list all the available network interfaces for your machine:

ip -6 addr

Find the network interface that you want to disable the IPv6 stack on. In my case, I want to disable it on my “enp1s0” Ethernet interface.

A terminal showing the Ethernet network interface for my machine.

Create a new config file for your IPv6 stack under “/etc/sysctl.d.”

sudo nano /etc/sysctl.d/40-ipv6.conf

Paste the following lines of code inside your new config file:

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.YOUR-INTERFACE-NAME.disable_ipv6 = 1

Save your new config file, then run the following commands to reload your new settings:

sudo sysctl -p /etc/sysctl.d/ipv6.conf
sudo systemctl restart systemd-sysctl.service

Go inside your machine’s hosts file, then add a pound (#) sign at the start of every line that contains an IPv6 address.

A terminal showing the IPv6 addresses in /etc/hosts disabled.

Create a backup of your machine’s original initramfs, then recreate it without IPv6 support:

sudo cp /boot/initramfs-$(uname -r).img /initramfs-backup.img
sudo dracut -f

Run the nmcli command and disable its IPv6 method for your interface. This ensures that your settings will persist across system reboots.

sudo nmcli connection modify YOUR-INTERFACE-NAME ipv6.method "disabled"

Lastly, reboot your system to apply your new settings.

FYI: learn more about how computers communicate over the network by looking at some simple and easy uses for Netcat.

Disable IPv6 on Debian-based Systems

Just like in Red Hat-based distros, you can also disable the IPv6 protocol from the userland of Debian-based systems. To do this, open a new terminal then run ip -6 addr to find the name of the interface that you want to disable IPv6 on:

A terminal highlighting the network interface with a running IPv6 stack.

Run the following commands to disable the IPv6 stack on a specific interface:

sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
sudo sysctl -w net.ipv6.conf.YOUR-INTERFACE-NAME.disable_ipv6=1

Apply the new settings by reloading your sysctl daemon and its Systemd service:

sudo sysctl -p
sudo systemctl restart systemd-sysctl.service

Disable the IPv6 method to ensure that Systemd will not overwrite your custom setting:

sudo nmcli connection modify YOUR-CONNECTION-NAME ipv6.method "disabled"

Note: You can find the name of your network interface in nmcli by running nmcli connnection show.

Check whether your network interface still has an IPv6 address by running ip addr.

A terminal showing the ethernet network interface without an IPv6 stack running.

Tip: if you are a Windows user, here is how you can disable IPv6 in Windows.

How to Re-enable IPv6 in Linux

To re-enable IPv6 in Linux, open your bootloader config file with your favorite text editor:

sudo nano /etc/default/grub

Press Ctrl + W, then search for “GRUB_CMDLINE_LINUX_DEFAULT.”

A terminal highlighting the Grub command line argument with an IPv6 flag.

Remove the ipv6.disable=1 value at the end of the variable.

A terminal showing the modified Grub command line argument without an IPv6 flag.

Save your config file, then reload your bootloader’s settings:

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

Reboot your system, then check if the IPv6 stack is back up and running.

A terminal showing the "/proc" filesystem running an IPv6 stack on the system.

Re-Enable IPv6 on Red Hat-based Systems

On Red Hat-based distros, you can re-enable IPv6 by editing the sysctl config file. To do this, open a new terminal session, then delete the “40-ipv6.conf” file under “/etc/sysctl.d/.”

sudo rm /etc/sysctl.d/40-ipv6.conf

Reload your sysctl daemon along with its Systemd service:

sudo sysctl -p
sudo systemctl restart systemd-sysctl.service

Open your “/etc/hosts” file, then remove the pound (#) sign in front of all the lines that contain an IPv6 address.

Restore the machine’s original initramfs back to its “/boot” partition:

sudo cp /initramfs-backup.img /boot/initramfs-$(uname -r).img
sudo dracut -f

Re-enable the IPv6 method on nmcli to ensure that Systemd will load the IPv6 stack on your network interface:

sudo nmcli connection modify YOUR-INTERFACE-NAME ipv6.method "auto"

Reboot your system to apply your new settings, then run ip -6 addr to confirm that the IPv6 stack is up and running.

Re-Enable IPv6 on Debian-based Systems

To restore the IPv6 stack on Debian-based distros, open a new terminal then run the following commands:

sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=0

Reload the sysctl daemon, as well as its Systemd service:

sudo sysctl -p
sudo systemctl restart systemd-sysctl.service

Enable the IPv6 stack for your network interface using nmcli:

sudo nmcli connection modify YOUR-CONNECTION-NAME ipv6.method "auto"

Lastly, confirm that your IPv6 stack is working properly by running ip -6 addr and checking if your interface has an IPv6 address.

A terminal showing the IPv6 stack running on Debian Linux.

Learning how to disable and re-enable the IPv6 stack in Linux is just the first step in getting into computer networking. Explore more of this deep and wonderful world by learning how to track packets in your network using Traceroute.

Image credit: Leon Seibert via Unsplash and Wikimedia Commons. All alterations and screenshots by Ramces Red.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Ramces Red
Ramces Red - Staff Writer

Ramces is a technology writer that lived with computers all his life. A prolific reader and a student of Anthropology, he is an eccentric character that writes articles about Linux and anything *nix.