How to temporarily disable IPv6 in Linux

See all GNU/Linux related FAQ
Sometimes, you may need to temporarily disable IPv6 in the Linux using net.ipv6.conf.all.disable_ipv6 kernel variable for testing purposes. You can use the sysctl command to turn IPv6 connectivity on or off without rebooting the system. For example, observe how your app or network reacts when IPv6 connectivity is suddenly lost and only IPv4 is available.

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Linux terminal
Category System Management
OS compatibility AlmaLinux Alpine Amazon Linux Arch CentOS Debian Fedora Linux Mint Mint openSUSE Pop!_OS RHEL Rocky Slackware Stream SUSE Ubuntu
Est. reading time 3 minutes
Advertisement

Testing IPv6 connectivity

Once you are connected to the IPv6-enabled (or dual-stack IPv4+IPv6-enabled) Internet or network, you can use the ping6 command or ping command to test network connectivity. The syntax is simple:
$ ping6 -c 4 google.com
$ ping -6 -c4 google.com
$ ping6 -c4 google.co.in

The following output confirms IPv6 connectivity:

PING google.co.in(maa03s40-in-x03.1e100.net (2404:6800:4007:825::2003)) 56 data bytes
64 bytes from maa03s40-in-x03.1e100.net (2404:6800:4007:825::2003): icmp_seq=1 ttl=57 time=70.8 ms
64 bytes from maa03s40-in-x03.1e100.net (2404:6800:4007:825::2003): icmp_seq=2 ttl=57 time=37.3 ms
64 bytes from maa03s40-in-x03.1e100.net (2404:6800:4007:825::2003): icmp_seq=3 ttl=57 time=40.0 ms
64 bytes from maa03s40-in-x03.1e100.net (2404:6800:4007:825::2003): icmp_seq=4 ttl=57 time=69.9 ms
 
--- google.co.in ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 37.343/54.505/70.752/15.856 ms

You can also use the ip command to find out how traffic will be routed to IPv6 gateway or interface on Linux
$ ip -6 route get 2404:6800:4007:825::2003
Outputs:

2404:6800:4007:825::2003 from :: via fe80::2802:2eff:fe79:bf64 dev wlp1s0 proto ra src 2401:4900:62f2:3007:4a89:e7ff:fe46:3066 metric 1024 mtu 1450 hoplimit 64 pref medium

Here is how to print IPv6 routing table on Linux:
$ ip -6 route show
The following table indicates that wlp1s0 is default interface for routing IPv6 traffic using fe80::2802:2eff:fe79:bf64:

2401:4900:62f2:3007::/64 dev wlp1s0 proto kernel metric 256 pref medium
fe80::/64 dev wlp1s0 proto kernel metric 256 pref medium
fe80::/64 dev lxdbr0 proto kernel metric 256 pref medium
fe80::/64 dev veth06dbf1f5 proto kernel metric 256 pref medium
fe80::/64 dev tapbb92aec1 proto kernel metric 256 pref medium
fe80::/64 dev tap352ea3ce proto kernel metric 256 pref medium
fe80::/64 dev veth7933c241 proto kernel metric 256 pref medium
default via fe80::2802:2eff:fe79:bf64 dev wlp1s0 proto ra metric 1024 expires 8986sec mtu 1450 hoplimit 64 pref medium

How to temporarily disable IPv6 in Linux for interface named wlp1s0

You can disable IPv6 for a specific interface named wlp1s0 as follows
$ sudo sysctl -w net.ipv6.conf.wlp1s0.disable_ipv6=1
Verify it:
$ sudo sysctl net.ipv6.conf.wlp1s0.disable_ipv6
To re-enable access for IPv6, enter:
$ sudo sysctl -w net.ipv6.conf.wlp1s0.disable_ipv6=0

You set net.ipv6.conf.all.disable_ipv6 to the value to 1 to disable IPv6 and 0 to enable IPv6.

Disabling IPv6 for all network interfaces on Linux

Type the sysctl command as follows:
$ sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
$ sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1

Verify it using the ping6 command:
$ ping6 google.com
And you will see:

ping6: connect: Cannot assign requested address

The following command should show no routing table for IPv6
$ ip -6 route show
Hence, there is no question of routing IPv6:
$ ip -6 route get 2404:6800:4007:825::2003
Again it will tell you it is not possible:

RTNETLINK answers: Network is unreachable

How to re-enable IPv6 on Linux for interfaces

Here is how to re-enable IPv6:
$ sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0
$ sudo sysctl -w net.ipv6.conf.default.disable_ipv6=0

Test it with the ping6 and ip commands as follows:
$ ping6 google.com
$ ip -6 route show
$ ip -6 route get 2404:6800:4007:825::2003

How to make these changes permanent

So far you learned how to use the sysctl command to make changes that are temporary. In other words, these changes will be lost after a Linux system reboots. For some reason, if you need IPv6 permanently disabled, edit the GRUB boot loader config file using a text editor. For example:
$ sudo vim  /etc/default/grub
Find GRUB_CMDLINE_LINUX_DEFAULT line. For example:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash fsck.mode=force"

Update as follows with “ipv6.disable=1” to disable IPv6 stack on Linux at the boot time. For example:

GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 quiet splash fsck.mode=force"

Save and close the file. Update config as follows:
# Debian/Ubuntu:
$ sudo update-grub
# RHEL/CentOS/Rocky/Alma/Fedora:
$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg

Reboot the Linux system using the “reboot,” “shutdown,” or “systemctl command“:
$ sudo reboot

Summing up

How to temporarily disable or enable IPv6 networking stack in Linux

How to temporarily disable or enable IPv6 networking stack in Linux (click to enlarge)

The most direct method to temporarily disable IPv6 is to use the sysctl command and set the net.ipv6.conf.all.disable_ipv6 and net.ipv6.conf.default.disable_ipv6 Linux kernel variables at runtime. This is useful in some cases:

  1. Some networks or applications may not fully support IPv6, leading to compatibility issues on your system. Disabling IPv6 temporarily can help troubleshoot and isolate problems related to network connectivity or application compatibility.
  2. Linux users, developers or sys/network admins may need to simulate IPv4-only environments for testing or development purposes.

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

0 comments… add one

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.