This article explains how to enable or disable IPv6 on Ubuntu Linux.
Most Ubuntu Linux devices have IPv4 and IPv6 enabled—no need to configure additional settings or install software to allow for these protocols.
However, you can disable and reenable IPv6 anytime. The steps below will give you some details on how to do that.
You can use multiple ways and files to turn IPv6 on or off on Ubuntu Linux. The most efficient way to do so is to use the /etc/sysctl.conf
file.
To disable IPv6 open the /etc/sysctl.conf
file using a text editor and add the following lines at the end of the file:
- 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 run the following command to apply the changes:
sudo sysctl -p
Remember that disabling IPv6 can cause issues with certain applications, so it is recommended only to do so if necessary.
If, for some reason, after rebooting, you get IPv6 reenabled, use the steps below to fix that.
Open the /etc/rc.local
file below.
sudo nano /etc/rc.local
Then copy and paste the lines below into the file and save it.
#!/bin/bash # /etc/rc.local /etc/sysctl.d /etc/init.d/procps restart exit 0
Run the commands below to enable the file to execute.
sudo chmod 755 /etc/rc.local
Turn IPv6 on or off using GRUB on Ubuntu Linux
System admins can also turn IPv6 on or off using the GRUB config file on Ubuntu Linux.
Run the command below to open the GRUB configuration file to do that.
sudo nano /etc/default/grub
Then locate the highlighted lines below.
# If you change this file, run 'update-grub' afterwards to update # /boot/grub/grub.cfg. # For full documentation of the options in this file, see: # info -f grub -n 'Simple configuration' GRUB_DEFAULT=0 GRUB_TIMEOUT_STYLE=hidden GRUB_TIMEOUT=0 GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian` GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" GRUB_CMDLINE_LINUX=""
Update the lines to look like the ones below.
# If you change this file, run 'update-grub' afterwards to update # /boot/grub/grub.cfg. # For full documentation of the options in this file, see: # info -f grub -n 'Simple configuration' GRUB_DEFAULT=0 GRUB_TIMEOUT_STYLE=hidden GRUB_TIMEOUT=0 GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian` GRUB_CMDLINE_LINUX_DEFAULT="quiet splash ipv6.disable=1" GRUB_CMDLINE_LINUX="ipv6.disable=1"
Save your changes and exit.
To apply the changes, run the commands below.
sudo update-grub
Reenable IPv6 on Ubuntu Linux
Once IPv6 is disabled, you can reenable it by reversing the steps above. First, run the command below one at a time.
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
Next, open the /etc/sysctl.conf
file and delete the lines added above at the end of the file.
sudo nano /etc/sysctl.conf
Save your settings by running the command below.
sudo sysctl -p
Delete the file created above.
sudo rm /etc/rc.local
Open the GRUB configuration file by running the command below.
sudo nano /etc/default/grub
Then change the highlighted lines below
# If you change this file, run 'update-grub' afterwards to update # /boot/grub/grub.cfg. # For full documentation of the options in this file, see: # info -f grub -n 'Simple configuration' GRUB_DEFAULT=0 GRUB_TIMEOUT_STYLE=hidden GRUB_TIMEOUT=0 GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian` GRUB_CMDLINE_LINUX_DEFAULT="quiet splash ipv6.disable=1" GRUB_CMDLINE_LINUX="ipv6.disable=1"
To the highlighted lines below.
# If you change this file, run 'update-grub' afterwards to update # /boot/grub/grub.cfg. # For full documentation of the options in this file, see: # info -f grub -n 'Simple configuration' GRUB_DEFAULT=0 GRUB_TIMEOUT_STYLE=hidden GRUB_TIMEOUT=0 GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian` GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" GRUB_CMDLINE_LINUX=""
Run the command below to update GRUB configurations.
sudo update-grub
Reboot your system, and IPv6 should be re-enabled.
That should do it!
Conclusion:
This post showed you how to disable or enable IPv6 on Ubuntu Linux. If you find any errors above or have something to add, please use the comments form below.