Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to disable IPv6 on Ubuntu Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is a detailed introduction to "how to disable IPv6 on Ubuntu Linux". The content is detailed, the steps are clear, and the details are properly handled. I hope this article "how to disable IPv6 on Ubuntu Linux" can help you solve your doubts. Let's go deeper and learn new knowledge together with the ideas of Xiaobian.

Because IPv4 has insufficient network address resources, it seriously restricts the application and development of the Internet. Therefore, the sixth version of the Internet Protocol, i.e. IPv6, can not only solve the problem of the number of network address resources, but also solve the obstacles for a variety of access devices to connect to the Internet. It has been observed that disabling IPv6 helps improve Ubuntu WiFi speeds in some cases.

Disable IPv6 on Ubuntu [power users]

Note: Most of the following commands entered into the terminal require root privileges (sudo).

Warning!

If you are a regular Linux desktop user and prefer a stable working system, avoid this tutorial, the next part is for users who know what they are doing and why.

1. Disable IPv6 with sysctl

First, you can check whether IPv6 is enabled by executing the following command:

ip a

If enabled, you should see an IPv6 address (the name of the network card may differ from the image)

To disable IPv6, you only need to enter three 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

Check if the command is valid:

ip a

If the command works, you should notice that the IPv6 entry disappears:

However, this method can only disable IPv6 temporarily, so IPv6 will still be enabled the next time the system boots.

(Temporarily disabled here means that the changes made this time are valid until the shutdown, because the relevant parameters are stored in memory and can change values, but they will be lost after the memory power is lost; in this sense, both methods described below are temporary, except that the timing of changing parameter values is early in the system startup and is applied every time the system is booted.) So how do you accomplish permanent change in that sense? The answer is to disable the relevant functions when compiling the kernel, and then regret only recompiling the kernel (sad).)

One way to keep the option in effect is to modify the file/etc/sysctl.conf, where I use vim to edit the file, but you can use any editor you want, and make sure you have administrator privileges (sudo):

Add the following lines (the same parameters used earlier) to the file:

net.ipv6.conf.all.disable_ipv6=1

net.ipv6.conf.default.disable_ipv6=1

net.ipv6.conf.lo.disable_ipv6=1

Execute the following command to apply settings:

sudo sysctl -p

If IPv6 is still enabled after the reboot and you want to continue with this approach, you must create the file/etc/rc.local (with root privileges) and add the following:

#!/ bin/bash

# /etc/rc.local

/etc/sysctl.d

/etc/init.d/procps restart

exit 0

Then use the chmod command to change the file permissions to make it executable:

sudo chmod 755 /etc/rc.local

This causes the system (at boot time) to read kernel parameters from the previously edited sysctl configuration file.

Disable IPv6 with GRUB

Another method is to configure GRUB, which passes parameters to the kernel at system startup. Doing so requires editing the file/etc/default/grub (make sure you have administrator privileges).

You now need to modify the two lines in the file that begin with GRUB_CMDLINE_LINUX_DEFAULT and GRUB_CMDLINE_LINUX, respectively, to disable IPv6 at boot time:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash ipv6.disable=1"

GRUB_CMDLINE_LINUX="ipv6.disable=1"

LCTT: This refers to adding the parameter ipv6.disable=1 in the above two lines. The default values of these two lines may vary from system to system.

Save the file and execute the command:

sudo update-grub

sudo grub-mkconfig -o/boot/grub/grub.cfg is required on systems without the update-grub command

Settings will take effect after restart.

Re-enable IPv6 on Ubuntu

To re-enable IPv6, you need to undo all previous changes. However, if you only want to temporarily enable IPv6, you can execute the following command:

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

Otherwise, if you want to keep it enabled, see if you have modified/etc/sysctl.conf, either by removing the previous additions or changing them to the following values (both methods are equivalent):

net.ipv6.conf.all.disable_ipv6=0

net.ipv6.conf.default.disable_ipv6=0

net.ipv6.conf.lo.disable_ipv6=0

Then apply settings (optional):

sudo sysctl -p

If IPv6 is temporarily enabled, there is no need to reload the configuration file.

You should see IPv6 addresses again:

Alternatively, you can delete the previously created file/etc/rc.local (optional):

sudo rm /etc/rc.local

If you modify the file/etc/default/grub, go back and delete the parameters you added:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

GRUB_CMDLINE_LINUX=""

Then update the GRUB configuration file:

sudo update-grub

Read here, this article "How to disable IPv6 on Ubuntu Linux" article has been introduced, want to master the knowledge of this article also need to practice to understand, if you want to know more about the content of the article, welcome to pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report