How to disable IPv6 in Ubuntu?

How To Disable IPv6 On Ubuntu 20.04LTS

In this article, We will learn how to disable IPv6 on Ubuntu 20.04LTS.

What is IPv6?

IPv6 or Internet Protocol version 6 is a communication protocol that provides an identification and location system for computers connected to the internet. It was designed by Internet Engineering Task Force (IETF) in 1998 to provide unique IP addresses as the original IP address scheme i.e. IPv4 is running out of addresses due to the increasing number of internet users. So, let’s see how to disable IPv6.

Method 1: Disabling IPv6 using Sysctl (Temporary)

To temporarily disable IPv6, follow these steps:

First of all, check whether Ipv6 is enabled or not by executing the following command:

ip a
ipv6-1

You will see an IPv6 address if it’s enabled, as shown above.

Now, to disable IPv6, run the following commands and check whether IPv6 is disabled or not by using the ip a command.

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
ipv6-2

This method disables Ipv6 only until you reboot your system. Whenever you boot your system again, IPv6 will be enabled again.

To re-enable it, Run the following commands:

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

Method 2: Disabling IPv6 using sysctl (Permanently)

Open the sysctl.conf file by running the following command (you can also use vim editor):

sudo vi /etc/sysctl.conf
ipv6-4

Now add these lines in the file and save and exit:

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

Run the following command for changes to take effect:

sudo sysctl -p
ipv6-6

This will disable IPv6 but sometimes after rebooting, IPv6 is enabled again. Now, Create a file /etc/rc.local by executing the following command:

sudo touch /etc/rc.local
ipv6-7

Open the file using the nano command:

sudo nano /etc/rc.local
ipv6-8

Add the following lines and save by pressing Ctrl+X.

#!/bin/bash
# /etc/rc.local

/etc/sysctl.d
/etc/init.d/procps restart

exit 0
ipv6-9

Now make the file executable by running the chmod command:

sudo chmod 755 /etc/rc.local
ipv6-10

That’s it, IPv6 will be disabled permanently until you manually enable it. Check by using the ip a command,

ipv6-11

In case, if you need to reenable IPv6, Delete the /etc/rc.local file by executing the following command:

sudo rm /etc/rc.local
ipv6-12

Ipv6 will be enabled again after reboot.

Method 3: Disabling IPv6 using GRUB

GRUB is the default Bootloader for all Linux distros. To disable IPv6 using this method, you need to edit /etc/default/grub file. Open the file by using nano:

sudo nano /etc/default/grub
ipv6-13

Now replace the following line:

GRUB_CMDLINE_LINUX=""
ipv6-14

with

GRUB_CMDLINE_LINUX="ipv6.disable=1"
ipv6-15

Save the file and exit. Now, Run the following command to update the GRUB boot menu and reboot.

sudo update-grub
ipv6-16

IPv6 will be disabled permanently.

Conclusion

So, we discussed how to disable Ipv6 using systemctl. You can disable IPv6 either temporarily or permanently. Modifying the Grub file is the easiest method to permanently disable IPv6.