How to PROPERLY disable IPv6 on Ubuntu? [SOLVED]


Written By - Omer Cakmak
Advertisement

What is IPv6?

IPv6 (Internet Protocol Version 6) was developed by the IETF after IPv4, which has a 32-bit address structure, is no longer sufficient for addressing. The size of the IPv6 address is 128 bits. IPv6 allows a packet to be forwarded to multiple destinations in a single sending operation. In other words, it allows multicasting.

Today, operating systems also support ipv6. However, when ipv6 is not widely used yet, it may cause problems if it is active in the system. Therefore, it should be disabled. In this article we will explain "How to disable ipv6 on Ubuntu".

 

How to check if ipv6 is enabled or disabled?

You can read more at 6 simple methods to check if ipv6 is enabled in Linux

You can see that ipv6 is active with the following command in Ubuntu:

foc@ubuntu22desktop:~$ ip ad

2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:1f:18:18 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.76/24 metric 100 brd 192.168.122.255 scope global dynamic enp1s0
       valid_lft 3586sec preferred_lft 3586sec
    inet6 fe80::5054:ff:fe1f:1818/64 scope link 
       valid_lft forever preferred_lft forever

In each of the methods we will describe below, you will be disabling ipv6.

 

Disable IPv6 Temporarily on Ubuntu

IPv6 can be disabled both temporarily and permanently. Sometimes it should be temporarily disabled. To do this, simply run the following commands in the terminal:

foc@ubuntu22:~$ sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.all.disable_ipv6 = 1

foc@ubuntu22:~$ sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6 = 1

foc@ubuntu22:~$ sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=1
net.ipv6.conf.lo.disable_ipv6 = 1

When you query the network information again with "ip a", you can see that the ipv6 line is missing:

foc@ubuntu22desktop:~$ ip a

2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:1f:18:18 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.75/24 brd 192.168.122.255 scope global dynamic noprefixroute enp1s0
       valid_lft 3586sec preferred_lft 3586sec

 

Disable IPv6 Permanently on Ubuntu

To disable ipv6 permanently, the following lines must be added to the /etc/sysctl.conf file:

Advertisement
foc@ubuntu22:~$ sudo nano /etc/sysctl.conf

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

Run sysctl -p to check that the lines are correct:

foc@ubuntu22:~$ sudo sysctl -p
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

To check that ipv6 is disabled:

foc@ubuntu22:~$ cat /proc/sys/net/ipv6/conf/all/disable_ipv6
1

If the output is 1, it indicates that ipv6 is disabled. Also take a look at the "ip a" output:

foc@ubuntu22desktop:~$ ip a

2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:1f:18:18 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.75/24 brd 192.168.122.255 scope global dynamic noprefixroute enp1s0
       valid_lft 3586sec preferred_lft 3586sec

IPv6 is permanently disabled.

 

Disable IPv6 in Grub Boot Loader

Although IPv6 is permanently disabled, it should also be disabled as kernel module. For this, the following settings must be entered in the grub boot loader settings:

Before:

foc@ubuntu22:~$ grep "GRUB_CMDLINE" /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX=""

After:

foc@ubuntu22:~$ sudo nano /etc/default/grub

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

Next update your GRUB configuration:

Advertisement
foc@ubuntu22:~$ sudo update-grub
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.15.0-56-generic
Found initrd image: /boot/initrd.img-5.15.0-56-generic
Found linux image: /boot/vmlinuz-5.15.0-46-generic
Found initrd image: /boot/initrd.img-5.15.0-46-generic
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
done

After this step, ipv6 has been disabled in grub loader.

 

Disable IPv6 in Netplan

If the network interface is configured with Netplan on the Ubuntu server, you must also disable IPv6 in the Netplan configuration file.

Before we start, let's see if ipv6 is active:

foc@ubuntu22desktop:~$ ip ad

2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:1f:18:18 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.76/24 metric 100 brd 192.168.122.255 scope global dynamic enp1s0
       valid_lft 3586sec preferred_lft 3586sec
    inet6 fe80::5054:ff:fe1f:1818/64 scope link 
       valid_lft forever preferred_lft forever

Then the network file is edited by opening it with an editor:

foc@ubuntu22:~$ sudo nano /etc/netplan/00-installer-config.yaml

Before:

# This is the network config written by 'subiquity'
network:
  ethernets:
    enp1s0:
      dhcp4: true
  version: 2

After:

Advertisement
# Let NetworkManager manage all devices on this system
network:
  ethernets:
    enp1s0:
      link-local: [ ipv4 ]
      dhcp4: true
  version: 2

Save and exit by adding the ipv4 line. Then the changes are applied:

foc@ubuntu22desktop:~$ sudo netplan apply

Network information is checked again:

foc@ubuntu22desktop:~$ ip ad

2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:1f:18:18 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.76/24 metric 100 brd 192.168.122.255 scope global dynamic enp1s0
       valid_lft 3598sec preferred_lft 3598sec

IPv6 has been disabled.

 

Disable IPv6 in NetworkManager

If you have a GUI server, you can disable IPv6 with the following steps.

Select SettingsNetwork

How to PROPERLY disable IPv6 on Ubuntu? [SOLVED]

 

Select IPv6DisableApply

disable ipv6

After this, reboot the server. Check the network settings after reboot, you will see that ipv6 is not available.

foc@ubuntu22desktop:~$ ip a

2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:1f:18:18 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.75/24 brd 192.168.122.255 scope global dynamic noprefixroute enp1s0
       valid_lft 3586sec preferred_lft 3586sec

 

Disable IPv6 in APT Package manager (Optional)

This step will not always be needed, but sometimes the apt package manager may need to use only ipv4. You can consider this information as an extra.

Create a file under apt.conf.d as follows:

sudo nano /etc/apt/apt.conf.d/99force-ipv4
Acquire::ForceIPv4 "true";

save the file and exit. Then, ipv4 will be used in apt operations.

Advertisement

 

Summary

We shared the steps to disable ipv6 with both the GUI and the terminal. It will be enough to undo the steps to enable IPv6.

 

References

askubuntu.com - Disable IPv6 on Ubuntu 20.04

 

Didn't find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Leave a Comment