How to disable ipv6 in linux

How to Disable IPv6 on Ubuntu Linux

Last updated October 29, 2020 By Sergiu 21 Comments

Are you looking for a way to disable IPv6 connections on your Ubuntu machine? In this article, I’ll teach you exactly how to do it and why you would consider this option. I’ll also show you how to enable or re-enable IPv6 in case you change your mind.

What is IPv6 and why would you want to disable IPv6 on Ubuntu?

Internet Protocol version 6 (IPv6) is the most recent version of the Internet Protocol (IP), the communications protocol that provides an identification and location system for computers on networks and routes traffic across the Internet. It was developed in 1998 to replace the IPv4 protocol.

IPv6 aims to improve security and performance, while also making sure we don’t run out of addresses. It assigns unique addresses globally to every device, storing them in 128-bits, compared to just 32-bits used by IPv4.

Although the goal is for IPv4 to be replaced by IPv6, there is still a long way to go. Less than 30% of the sites on the Internet makes IPv6 connectivity available to users (tracked by Google here). IPv6 can also cause problems with some applications at time.

Since VPNs provide global services, the fact that IPv6 uses globally routed addresses (uniquely assigned) and that there (still) are ISPs that don’t offer IPv6 support shifts this feature lower down their priority list. This way, they can focus on what matters the most for VPN users: security.

Another possible reason you might want to disable IPv6 on your system is not wanting to expose yourself to various threats. Although IPv6 itself is safer than IPv4, the risks I am referring to are of another nature. If you aren’t actively using IPv6 and its features, having IPv6 enabled leaves you vulnerable to various attacks, offering the hacker another possible exploitable tool.

On the same note, configuring basic network rules is not enough. You have to pay the same level of attention to tweaking your IPv6 configuration as you do for IPv4. This can prove to be quite a hassle to do (and also to maintain). With IPv6 comes a suite of problems different to those of IPv4 (many of which can be referenced online, given the age of this protocol), giving your system another layer of complexity.

It has also been observed that disabling IPv6 helps to improve WiFi speed in Ubuntu in some cases.

Disabling IPv6 on Ubuntu [For Advanced Users Only]

In this section, I’ll be covering how you can disable IPv6 protocol on your Ubuntu machine. Open up a terminal (default: CTRL+ALT+T) and let’s get to it!

Note: For most of the commands you are going to input in the terminal you are going to need root privileges (sudo).

If you are a regular desktop Linux user and prefer a stable working system, please avoid this tutorial. This is for advanced users who know what they are doing and why they are doing so.

1. Disable IPv6 using Sysctl

First of all, you need to make sure that you have IPv6 enabled on your system. Check your IP address in Ubuntu with this command:

You should see an IPv6 address if it is enabled (the name of your internet card might be different):

You have see the sysctl command in the tutorial about restarting network in Ubuntu. We are going to use it here as well. To disable IPv6 you only have to input 3 commands:

You can check if it worked using:

You should see no IPv6 entry:

However, this only temporarily disables IPv6. The next time your system boots, IPv6 will be enabled again.

One method to make this option persist is modifying /etc/sysctl.conf. I’ll be using vim to edit the file, but you can use any editor you like. Make sure you have administrator rights (use sudo):

Add the following lines to the file:

Читайте также:  Как отключить службу защитник windows 10 навсегда

For the settings to take effect use:

If IPv6 is still enabled after rebooting, you must create (with root privileges) the file /etc/rc.local and fill it with:

Now use chmod command to make the file executable:

What this will do is manually read (during the boot time) the kernel parameters from your sysctl configuration file.

2. Disable IPv6 using GRUB

An alternative method is to configure GRUB to pass kernel parameters at boot time. You’ll have to edit /etc/default/grub. Once again, make sure you have administrator privileges:

Grub Configuration 1

Now you need to modify GRUB_CMDLINE_LINUX_DEFAULT and GRUB_CMDLINE_LINUX to disable IPv6 on boot:

Save the file and run the update-grub command:

The settings should now persist on reboot.

Re-enabling IPv6 on Ubuntu

To re-enable IPv6, you’ll have to undo the changes you made. To enable IPv6 until reboot, enter:

Otherwise, if you modified /etc/sysctl.conf you can either remove the lines you added or change them to:

You can optionally reload these values:

You should once again see a IPv6 address:

Optionally, you can remove /etc/rc.local:

If you modified the kernel parameters in /etc/default/grub, go ahead and delete the added options:

Wrapping Up

In this guide I provided you ways in which you can disable IPv6 on Linux, as well as giving you an idea about what IPv6 is and why you would want to disable it.

Did you find this article useful? Do you disable IPv6 connectivity? Let us know in the comment section!

Like what you read? Please share it with others.

Источник

How to disable or enable ipv6 in Linux

There are many methods which can be used to disable IPv6 depending upon your requirement so I will try to explain the ones which I am aware of and I have used in my setup

Disable IPv6 for individual interface

NOTE: This actually does not deactivates the ipv6 modules instead it will disable Ipv6 for this particular interface

Currently I have bond0 on my node which has IPv6 enabled as you can see below
bond0: flags=5187 mtu 1500
inet 10.43.138.1 netmask 255.255.255.224 broadcast 10.43.138.31
inet6 fe80::92f4:cdc0:37ea:9ff6 prefixlen 64 scopeid 0x20

ether 00:17:a4:77:00:02 txqueuelen 1000 (Ethernet)
RX packets 223 bytes 28496 (27.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 191 bytes 26556 (25.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
To disable the same for bond0 I can use either of below steps

Add the below variable (if it does not exist already) and remove all other IPv6 related variable from the config file
# vi /etc/sysconfig/network-scripts/ifcfg-bond0
IPV6INIT=no
Restart you network services
# systemctl restart network.service
But this will not do the magic yet, since currently ipv6 is enabled for bond0 in sysctl.conf file as we can see below
# sysctl -a | grep net.ipv6.conf.bond0.disable_ipv6
net.ipv6.conf.bond0.disable_ipv6 = 0
Disable the same by adding below line in /etc/sysctl.conf. First make sure you do not have any entry for this value
# grep “net.ipv6.conf.bond0.disable_ipv6” /etc/sysctl.conf
If the output is blank add the below line and if you already find an existing entry then change value of “0” to “1” or else execute below command
# echo “net.ipv6.conf.bond0.disable_ipv6=1” >> /etc/sysctl.conf
Refresh the sysctl values
# sysctl -p
Then rebuild the Initial RAM Disk Image using
# dracut -v -f
Next check the ipv6 status for bond0
# ifconfig
bond0: flags=5187 mtu 1500
inet 10.43.138.1 netmask 255.255.255.224 broadcast 10.43.138.31
ether 00:17:a4:77:00:02 txqueuelen 1000 (Ethernet)
RX packets 317 bytes 35564 (34.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 251 bytes 38566 (37.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
The same list of step can be followed for any other individual interface for which you want to disable the ipv6

Disable IPv6 for the complete node (for all interfaces)

After doing the above list of steps still I have Ipv6 enabled for my loopback address and bond3 which I am using
# ifconfig | grep inet6
inet6 fe80::73f1:af4c:dc8:ac prefixlen 64 scopeid 0x20

inet6 ::1 prefixlen 128 scopeid 0x10
So now I want to disable them completely

Here we need not use the individual interface files and we can directly disable ipv6 using our GRUB.
NOTE: This would require a REBOOT of the system to activate the changes

Append “ ipv6.disable=1 ” in “ /etc/default/grub ” file as shown below
GRUB_CMDLINE_LINUX=”ipv6.disable=1 crashkernel=auto rd.lvm.lv=system/root rd.lvm.lv=system/usr biosdevname=0 net.ifnames=0 rhgb quiet”
Next regenerate the grub2 configuration file using
# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file …
Found linux image: /boot/vmlinuz-3.10.0-514.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-514.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-a311757619b943238cda551a0f1b2743
Found initrd image: /boot/initramfs-0-rescue-a311757619b943238cda551a0f1b2743.img
done

If you have a UEFI based BIOS enabled node, also execute below command
# grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
Lastly proceed with the reboot of the node to activate the changes

Enable IPv6 on RHEL

This actually would depend pretty much on the steps you followed to disable the IP6 and accordingly vice versa steps must be followed. For the sake of this article I would use the steps as explained above to re-enable IPv6

Читайте также:  Lenovo e555 windows 10

Источник

Как отключить IPv6 в Ubuntu

Протокол IPv6 — это новая технология, которая предоставляет намного большее адресное пространство IP адресов, более высокую безопасность и скорость работы. Но это все в идеале. IPv6 нарушает обратную совместимость с IPv4 и сейчас в большинстве случаев используется старый протокол. Мы уже очень подробно рассматривали чем отличается IPv6 от IPv4, поэтому не будем повторять все еще раз.

Поскольку на данный момент IPv6 используется достаточно редко, этот протокол полностью поддерживается далеко не всем оборудованием. Если IPv6 не поддерживается вашим роутером или провайдером, то это замедлит работу сети, дольше будут определяться доменные имена сайтов и будет выполняться попытка получения IPv6 адреса, что тоже приведет к задержке. В этой небольшой заметке мы рассмотрим как отключить IPv6 в Ubuntu или других совместимых дистрибутивах.

Проверка поддержки IPv6

Все современные дистрибутивы поддерживают IPv6 без исключений. Но чтобы убедиться что ваша локальная машина получила ipv6 адрес вы можете выполнить команду:

В разделе для подключения eth0 вы увидите адрес inet4 и inet6, в inet6 будет показан адрес Ipv6, который присвоен этому компьютеру роутером. Все адреса, начинающиеся с fe80 — это адреса локальных сетей. Но присутствие этого адреса еще не означает, что он поддерживается вашим провайдером. Для проверки этого пункта можно попытаться отправить ping запрос на ipv6.google.com:

Если вы увидите привычный ответ о времени доставки пакетов, то значит все работает, но если ipv6 провайдером не поддерживается вы получите network unreachable или что-то в этом роде. В таком случае IPv6 лучше отключить чтобы интернет работал быстрее.

Как отключить IPv6 в Ubuntu

Есть несколько способов отключить IPv6 Ubuntu мы рассмотрим их все.

Способ 1. С помощью sysctl

Первый способ решения нашей задачи, это редактирование параметров ядра во время выполнения с помощью sysctl. Для отключения IPv6 выполните:

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

Вы можете также пойти другим путем и записать все эти значения в файл настройки, чтобы они применялись по умолчанию при старте системы:

sudo vi /etc/sysctl.conf

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

Сохраните файл, закройте его и перезапустите sysctl для обновления конфигурации:

Теперь, когда вы выполните ip addr show, здесь не должно быть ipv6 адреса:

Способ 2. Отключить ipv6 в Grub

Вы также можете отключить IPv6 отредактировав параметры загрузки ядра в Grub. Для этого откройте файл /etc/default/grub и добавьте туда такую строку:

sudo vi /etc/default/grub

GRUB_CMDLINE_LINUX = «ipv6.disable = 1»

Если переменная GRUB_CMDLINE_LINUX уже существует то вы можете добавить это значение в конец строки к другим параметрам. После завершения сохраните изменения и обновите конфигурацию Grub с помощью команды:

После перезагрузки отключение ipv6 Ubuntu 16.04 будет завершено и ваша сеть станет работать быстрее.

Выводы

В этой статье мы рассмотрели как отключить ipv6 linux как видите, это очень просто. Возможно, вы и не знали раньше, но если ваш провайдер не поддерживает этот протокол, то его лучше отключить.

Источник

How to disable IPv6 in Linux?

Internet Protocol version 6 (IPv6) is the most recent version of the Internet Protocol (IP), the communications protocol that provides an identification and location system for computers on networks and routes traffic across the Internet. IPv6 was developed by the Internet Engineering Task Force (IETF) to deal with the long-anticipated problem of IPv4 address exhaustion. IPv6 is intended to replace IPv4. IPv6 is relatively new and sometimes depending on how it’s configured, it can behave badly. This post will show how to disable IPv6 in Linux distro such as Ubuntu, Debian, Kali, Linux Mint etc.

Every device on the Internet is assigned an IP address for identification and location definition. With the rapid growth of the Internet after commercialization in the 1990s, it became evident that far more addresses than the IPv4 address space has available were necessary to connect new devices in the future. By 1998, the Internet Engineering Task Force (IETF) had formalized the successor protocol. IPv6 uses a 128-bit address, allowing 2128, or approximately 3.4×1038 addresses, or more than 7.9×1028 times as many as IPv4, which uses 32-bit addresses and provides approximately 4.3 billion addresses. The two protocols are not designed to be interoperable, complicating the transition to IPv6. However, several IPv6 transition mechanisms have been devised to permit communication between IPv4 and IPv6 hosts.

IPv6 provides other technical benefits in addition to a larger addressing space. In particular, it permits hierarchical address allocation methods that facilitate route aggregation across the Internet, and thus limit the expansion of routing tables. The use of multicast addressing is expanded and simplified, and provides additional optimization for the delivery of services. Device mobility, security, and configuration aspects have been considered in the design of the protocol.

IPv6 addresses are represented as eight groups of four hexadecimal digits with the groups being separated by colons, for example 2001:0db8:85a3:0042:1000:8a2e:0370:7334, but methods to abbreviate this full notation exist. However it is not yet widely supported and its adoption is still in progress.

Читайте также:  Windows store моя библиотека

Does your system support IPv6 ?

To make IPv6 work, you need an Operating System that supports IPv6. Ubuntu, Debian, Linux Mint and most modern distros does that. You can check output of ifconfig to see if IPv6 is working and whether it’s assigned to the network interfaces:

Check the line inet6 addr

Next you need a router/modem that also supports IPv6. And beyond that, your ISP must also support IPv6.

Instead of checking every part of the network infrastructure, its better to just find out if you can connect to websites over IPv6. There are lots of websites that test IPv6 support on your connection. Check out http://testmyipv6.com/ for example.

The kernel parameters that enable IPv6 are as follows

The same can be also be checked from the proc files

Note that the variables control disabling of IPv6. So setting them to 1 would disable IPv6

Disable IPv6 if its not supported

So if IPv6 is not supported on your network infrastructure, it might be useful to disable it all together. Why ? It can cause issues like delayed domain lookups, un-necessary attempts to connect to IPv6 addresses causing delay in network connection etc.

I did come across some problems like that. The apt-get command occasionally tries to connect to IPv6 addresses and fails and then retries an ipv4 address. Take a look at this output

Errors like those have been more frequent in the recent Ubuntu versions, probably because they try to use IPv6 more than before.

I noticed similar issues happen in other applications like Hexchat and also Google Chrome which would sometimes take longer than usual to lookup a domain name.

So the best solution is to disable IPv6 entirely to get rid of those things. It takes only a small configuration and can help you solve many network issues on your system. Users have even reported an increase in internet speed.

Method 1 – Disable IPv6

Edit the file – /etc/sysctl.conf

And fill in the following lines at the end of that file

Save the file and close it

Restart sysctl with

Check the output of ifconfig again and there should be no ipv6 address

If it does not work, then try rebooting the system and check ifconfig again.

Method 2 – Disable IPv6 – GRUB method

IPv6 can also be disabled by editing the grub configuration file

Look for the line containing GRUB_CMDLINE_LINUX and edit it as follows

The same can also be added to the value of the variable named GRUB_CMDLINE_LINUX_DEFAULT and either would work. Save the file, close it and regenerate the grub configuration

Reboot. Now IPv6 should be disabled.

Method 3 – Without disabling IPv6 – setting IPv4 as preferred over IPv6

Find at getaddrinfo(3) s configuration file; i.e. /etc/gai.conf and uncomment the line to prefer IPv4 over IPv6.

Locate this line and un-comment it:

So that it looks like this:

Save and exit the file. Reboot and you’re all set as IPv4 is preferred now. This is the best way when you want to keep IPv6 enabled but prefer IPv4 for DNS lookup or such.

Conclusion

Disabling IPv6 can cause problems. If your Internet connection and router have already migrated to IPv6, you’ll lose the ability to use it properly. IPv6 may also be required for some home networking functions — for example, the easy-to-use Homegroup home networking feature introduced in Windows 7, Linux etc. requires IPv6 enabled on the computers on your home network to use it.

The entire world is moving towards IPv6, although it’s happening too slowly. IPv6 is necessary to replace IPv4 — we’re running out of IPv4 addresses and IPv6 is the solution. In that context, the last method of setting preferences (Without disabling IPv6 – setting IPv4 as preferred over IPv6) is better. There’s a good chance you don’t actually need IPv6 on your network — unless you rely on Windows Homegroup or similar features — so it may not be particularly harmful to remove if if you know what you’re doing. However, you won’t see a speed improvement from clinging to IPv4 unless there are serious problems with your Internet service provider’s network or your home network.

The moral is, if you notice that IPv6 needs fixing, fix it today rather than postponing until tomorrow. We live in the early days of mass deployment of IPv6, and we need to work together to untangle the implementation quirks that arise. The list of fixes above represents only a small sampling of potential issues. You can always seek help Online at any number of reputable IPv6 discussion forums. Use network misbehavior as an opportunity to learn about and improve the state of IPv6 internetworking and resist any temptations to disable the protocol.

Источник

Оцените статью