If you are looking for a way to disable IPv6 then this guide is for you. Here I will discuss why you need to disable IPv6 and different methods to disable it on a Ubuntu system.
What is IPv6?
Before we proceed in our discussion let’s discuss a little bit about IPv6.
An IP address is a unique identifier that is assigned to each device connected to a computer network and uses Internet protocol for communication. A computer uses this address to send data to a specific computer.
There are two versions of IP addresses –
- IPv4
- IPv6
Every computer connected to the internet uses an IPv4 address and many of them are starting to use IPv6. IPv6 is developed by IETF(Internet Engineering Task Force) to deal with the long-anticipated problem of IPv4 exhaustion.
IPv6 address has 8 groups of hexadecimal numbers each separated by a colon. It uses 128 bits for a single IPv6 address.
Example of IPv6 address is 2606:2800:220:1:248:1893:25c8:1946
Why someone wants to disable IPv6 on Ubuntu
According to Google’s statistics on IPv6 adoption as of now, less than 35% of sites on the internet are using IPv6 addresses. It can cause problems with some applications. For example, VPN services that offer secure browsing IPv6 aren’t working at all or isn’t working as well. There are many reports that show information leakage from VPN communication using IPv6. That means it is not secure as it does with IPv4 transmission.
You may have existing devices that support only IPv4 so you need to switch to IPv4 to communicate with them. Another reason could be that your current ISP does not offer IPv6 addressing.
There can be certain problems after upgrading to IPv6 services for instance a server that runs multiple services, some of which are IPv4 only, and others that are both IPv4 and IPv6 can experience problems. Some clients might need to use both types of services, which leads to confusion on the server-side.
How to disable IPv6 on Ubuntu
To disable the IPv6 on a Ubuntu system open the terminal by pressing ctrl+alt+t.
First, check if IPv6 is enabled on your system or not –
ip a
This will display the output something like this –
If it is enabled you will see the IPv6 address as highlighted in the given image.
Method 1: By editing /etc/sysctl.conf file
To disable the IPv6 use the given commands on your system –
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
Now if you check the IPv6 address on your system you will find it is missing. However, this will not disable IPv6 permanently. To make the changes persistent open the /etc/sysctl.conf
file.
sudo nano /etc/sysctl.conf
and then add the following entries –
net.ipv6.conf.all.disable_ipv6=1 net.ipv6.conf.default.disable_ipv6=1 net.ipv6.conf.lo.disable_ipv6=1
Save the file and exit from the editor. Now use the given command to make all the changes effective –
sudo sysctl -p
If IPv6 is still enabling then you should create the /etc/rc.local
(with root privileges) and fill it with the given –
#!/bin/bash # /etc/rc.local /etc/sysctl.d /etc/init.d/procps restart exit 0
Save this file and use the given command to make it executable.
sudo chmod 755 /etc/rc.local
This will make manually read the kernel parameters from the sysctl configuration file and boot time.
Method 2: Disabling IPv6 using GRUB
This is the recommended method to disable the IPv6 we can configure the GRUB boot loader to pass kernel parameters during the boot time.
To do this open the /etc/default/grub
file using a text editor with root privileges-
sudo nano /etc/default/grub
and replace the given text –
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" GRUB_CMDLINE_LINUX=""
with the following one –
GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1" GRUB_CMDLINE_LINUX="ipv6.disable=1"
Now after modification, the grub configuration file will look as given below.
sudo update-grub
How to re-enable IPv6 on Ubuntu
To re-enable the IPv6 you need to undo the changes that you made. If you disabled the IPv6 using the first method then run –
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
OR if you make changes to the /etc/sysctl.conf
file then open it with a text editor and remove all the given lines that you have added.
net.ipv6.conf.all.disable_ipv6=1 net.ipv6.conf.default.disable_ipv6=1 net.ipv6.conf.lo.disable_ipv6=1
Save this file and exit from the editor.
and if you have modified the /etc/rc.local
file then delete it from your system.
sudo rm /etc/rc.local
If you disabled the IPv6 using the second method then you need to replace the given –
GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1" GRUB_CMDLINE_LINUX="ipv6.disable=1"
With the following one –
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" GRUB_CMDLINE_LINUX=""
Conclusion
Now you know how to disable or enable the IPv6 on your Ubuntu system. If you have a query then write us in the comments below.