Disable IPv6 in Ubuntu/Debian

PowerADM.com / Linux / Debian / Disable IPv6 in Ubuntu/Debian

IPv6 protocol is enabled by default in all modern Linux distros. You can disable IPv6 on Linux if you only use IPv4 addressing on your network. This article shows how to disable IPv6 in Ubuntu and Debian Linux.

Check that an IPv6 interface is available on the host:

$ ip addr | grep inet6

inet6 ::1/128 scope host
inet6 fe80::7cd3:2e4f:d06e:3ee6/64 scope link noprefixroute

check if IPv6 is enabled on ubuntu

Check if there are any active listeners on Linux waiting for connection on IPv6 interfaces.

$ ss -lnptu | sort

Edit the sysctl.conf file to disable IPv6 support for all interfaces at once:

$ sudo mcedit /etc/sysctl.conf

Add the following lines to the end of the configuration file:

# disable IPv6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
net.ipv6.conf.ens33.disable_ipv6 = 1

In the last line, enter the name of the interface you want to disable IPv6 on, in our example, ens33 (you can list network interfaces on Linux using the ip a command).

disable ipv6 in sysctl.conf

To apply the change in sysctl.conf, you need to run the command:

$ sudo sysctl –p

Or ( on Debian 10):

$ sudo /sbin/sysctl -p

Run the following command and check that Linux has no IPv6-enabled interfaces:

$ ip addr | grep inet6

You can also check that IPv6 is disabled with the command (should return 1):

$ cat /proc/sys/net/ipv6/conf/all/disable_ipv6

This way of disabling IPv6 works in recent versions of Ubuntu LTS 22.04 and Debian Bullseye 11.2.

If you need to temporarily disable IPv6 until the next time you restart your computer, run the commands:

$ sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
$ sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1

You can also disable IPv6 through the kernel options in GRUB. Edit the GRUB configuration file:

$ sudo mcedit /etc/default/grub

Add the following lines to the end of the file:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash ipv6.disable=1"
GRUB_CMDLINE_LINUX="ipv6.disable=1"

Save the file and update the GRUB configuration:

$ sudo update-grub

This will disable IPv6 at Linux boot.

Leave a Reply

Your email address will not be published. Required fields are marked *