How to disable and enable IPv6 address on Ubuntu 20.04
IPv6, Internet Protocol version 6 is the most recent version of the Internet Protocol (IP). It is a communications protocol which is used for identification and location for computers on networks. Its purpose it to route traffic across the Internet. This article will show you how to temporarily or permanently disable IPv6 on Ubuntu 20.04
Disable IPv6 on Ubuntu [Advanced Users Only]
- In this section, I will demonstrate how you can disable the IPv6 protocol on your Ubuntu machine. Open a terminal
Note: For most commands you will type in the terminal, you will need root privileges ( sudo ).
- Warning! :If you are a regular desktop Linux user and prefer a stable operating system, please avoid this guide. This is for advanced users who know what they are doing and why they are doing it.
1. How to disable IPv6
First of all, you need to make sure that you have IPv6 enabled on your system. Check your IP address in Ubuntu with the following command:
$ ip a
You should see the IPv6 address if it is enabled (your internet card name may be different):
You have seen the sysctl command in the tutorial on how to restart the network in Ubuntu. We will also use it here. To disable IPv6, you only have to enter 3 commands:
$ 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
You can check if it works by using:
$ ip a
Ubuntu Disabled IPv6
-However, this only temporarily disables IPv6 . The next time your system boots, IPv6 will be re-enabled.
One method to make this option exist is to modify /etc/sysctl.conf . I’m going to use nano to edit the file, but you can use any editor you like. Make sure you have admin rights (use sudo ):
$ nano /etc/sysctl.conf
Add the following lines to the file:
net.ipv6.conf.all.disable_ipv6=1 net.ipv6.conf.default.disable_ipv6=1 net.ipv6.conf.lo.disable_ipv6=1
For the settings to take effect, use:
$ sudo sysctl -p
If IPv6 is still enabled after reboot, you must create (with root privileges) the file /etc/rc.local and fill it with:
#!/bin/bash # /etc/rc.local /etc/sysctl.d /etc/init.d/procps restart exit 0
Now use the chmod command to make the file executable
$ sudo chmod 755 /etc/rc.local
What this will do is manually read (during boot time) the kernel parameters from your sysctl configuration file.
2. How to re-enable IPv6 on Ubuntu
To re-enable IPv6, you will have to undo the changes you made. To enable IPv6 until reboot, type:
$ 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
Conversely, if you modify /etc/sysctl.conf, you can remove the lines you added or change them to:
net.ipv6.conf.all.disable_ipv6=0 net.ipv6.conf.default.disable_ipv6=0 net.ipv6.conf.lo.disable_ipv6=0
You can optionally reload these values:
$ sudo sysctl -p
Again you will see the IPv6 address:
Optionally, you can remove /etc/rc.local :\
$ sudo rm /etc/rc.local
In this guide, I’ve given you ways you can disable IPv6 on Linux, as well as giving you an idea of what IPv6 is and why you want to disable it.