You might be wondering why you would want to disable IPv6 on your Ubuntu device. Perhaps you are having trouble connecting to certain devices or websites. Or maybe you’re just curious about this newer protocol. In any case, this tutorial will show you how to either temporarily or permanently disable IPv6 on Ubuntu 22.04 LTS.
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=1
The above commands will temporarily disable IPv6, meaning that the settings will not persist after reboot. To re-enable IPv6 reboot your system or execute the above commands again, however reverse the logic and change 1 to 0.
An alternative method is to configure GRUB to pass kernel parameters at boot time. You’ll have to edit /etc/default/grub.
sudo nano /etc/default/grub
Now you need to modify:
GRUB_CMDLINE_LINUX_DEFAULT and GRUB_CMDLINE_LINUX to disable IPv6 on boot:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash ipv6.disable=1" GRUB_CMDLINE_LINUX="ipv6.disable=1"
sudo update-grub