Linux disable ipv6 ubuntu

How to Disable IPv6 on Ubuntu Linux

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.

Disable IPv6 Ubuntu

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.

Читайте также:  Linux files opened by process

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):

Ipv6 Address Ubuntu

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:

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

You can check if it worked using:

You should see no IPv6 entry:

Ipv6 Disabled Ubuntu

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):

Sysctl Configuration

Add the following lines to the file:

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

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:

#!/bin/bash # /etc/rc.local /etc/sysctl.d /etc/init.d/procps restart exit 0

Now use chmod command to make the file executable:

sudo chmod 755 /etc/rc.local

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

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

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

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:

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 modified /etc/sysctl.conf you can either remove the lines you added or change them to:

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

You can optionally reload these values:

You should once again see a IPv6 address:

Ipv6 Address Ubuntu 1

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

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

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" GRUB_CMDLINE_LINUX=""

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!

Источник

2 Ways to Disable IPv6 on Ubuntu Desktop & Server

This tutorial is going to show you how to disable IPv6 on Ubuntu. Why do you want to disable IPv6? Although IPv6 is the future, right now many systems and applications still rely on IPv4 and may not work well with IPv6.

Читайте также:  Get listening port linux

For example, if a software repository supports IPv6, then the APT package manager will connect to that repository via IPv6 regardless of whether or not your ISP supports IPv6, as shown in the screenshot below.

disable ipv6 ubuntu

Method 1: Disable IPv6 on Ubuntu via GRUB Boot Loader

This is the easiest method, but it requires you to reboot your computer.

GRUB is the standard boot loader on Linux distributions. Edit the GRUB configuration file with a command-line text editor like Nano.

GRUB_CMDLINE_LINUX="ipv6.disable=1"

Disable IPv6 on Ubuntu via GRUB Boot Loader

Save and close the file. (Press Ctrl+O , then press Enter to save a file in Nano text editor. Next, press Ctrl+X to exit.)

Method 2: Disable IPv6 on Ubuntu via sysctl

You can disable IPv6 on your Ubuntu Linux system by making some changes to Linux kernel parameter.

Instead of the editing the /etc/sysctl.conf file, we create a custom config file ( 60-custom.conf ) so the changes can be preserved when you upgrade Ubuntu.

sudo nano /etc/sysctl.d/60-custom.conf

Copy and paste the following 3 lines to this file.

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

If your computer has a wireless card, you also need to add the following line to the file. Replace wlan0 with the name of your own wireless network interface.

net.ipv6.conf.wlan0.disable_ipv6 = 1

Save and close the file. Then execute the following commands to apply the above changes.

sudo sysctl -p sudo systemctl restart procps

Now run the following command. You should see 1 , which means IPv6 has been successfully disabled.

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

disable ipv6 on ubuntu 16.04

Parameters defined in 60-custom.conf file is preserved across reboot, so IPv6 won’t be enabled next time you boot up Ubuntu unless you manually re-enable it.

To re-enable IPv6 on Ubuntu, simply remove those 3 lines in 60-custom.conf file and run sudo sysctl -p command to load the changes.

Disable IPv6 in Netplan

If you run an Ubuntu server and your network interface is configured with Netplan, then you also need to disable IPv6 in the Netplan configuration file. For example, I set up my Wi-Fi connection from the command line in the /etc/netplan/10-wifi.yaml file. I need to add link-local: [ ipv4 ] to the file, so Netplan will enable only IPv4 for my wireless interface.

ubuntu disable ipv6 in netplan

Run the following command after making changes to Netplan config files.

Disable IPv6 in NetworkManager

If you use Ubuntu desktop, then when your computer resumes from suspend, NetworkManager will reconnect your computer to the router, and it can give your computer an IPv6 address. So we also need to disable IPv6 in NetworkManager. It’s very simple. Go to your network settings, choose the IPv6 tab and disable IPv6.

disable ipv6 in network manager

Click the Apply button. Then restart Network Manager with the following command.

sudo systemctl restart NetworkManager

Disable IPv6 in APT

Sometimes, you need to disable IPv6 in the APT package manage only and other programs can continue to use IPv6 if needed. To disable IPv6 in APT, run the following command to create a configuration file for APT.

sudo nano /etc/apt/apt.conf.d/99force-ipv4

Copy and paste the following line into the file.

Save and close the file. From now on, APT will use IPv4 only.

That’s it! I hope this tutorial helped you disable IPv6 on Ubuntu desktop and server.

16 Responses to “2 Ways to Disable IPv6 on Ubuntu Desktop & Server”

Many thanks! I’d just recently setup ‘Graylog’ as sort of a light SIEM solution for my lab network, and wanted to eliminate all internal IPv6 chatter. This cleared it right up. Also, it worked across Ubuntu 14.04 and Debian 8 (Jessie) and Debian 9 (stretch), aside from Ubuntu 16.04.3.

Читайте также:  Настройка динамической маршрутизации linux

For those who didn’t work suggest use also those command modyfiyng it, according to your interface name, repleace enp0s25 with your interface name:

sudo ip addr flush enp0s25 sudo systemctl restart networking.service

No real need to disable IPv6, really.
If you don’t have a IPv6 router in the LAN, your computer will not use IPv6.
If you do have a IPv6 router in the LAN, and it doesn’t work, then fix the problem, not the symptom. Fix the router. And by the way, IPv6 are faster then IPv4.

“Fix the router” assumes that you have control over the router, of course, and even if you can, it only fixes the problem for *one* network. It’s much better to fix the problem once and for all by definitely turning off IPv6. Then you know you are protected no matter which network you are connecting to.

Presto – no more worrying that connecting to a sketchy airport WiFi might expose you with a public IP address.

Thanks for the guide. All worked except on my Ubuntu 18.04 LTS the command “sudo sysctl -p” didn’t reload the variables. Instead I used the following command to update the IPV6 related variables:

sudo service procps reload

For ubuntu 20.10 server, DO NOT use sysctl.conf or Netplan methods. when I used sysctl.conf method, it made it worse. After reboot, it added inet6 IPs even it was disabled (value = 1) for cat /proc/sys/net/ipv6/conf/all/disable_ipv6. Go with Grub method.

Regarding the netplan option and Ubuntu Server 21.04, if you don’t also use the ‘dhcp4: false’ (picture shows ‘dhcp4: no’) below the link-local line, you might get a 169.254 address. I started with no ‘link-local’ option and no ‘dhcp4:’ option which means ipv6 is enabled. Add the link-local option and 169.254 address shows up. Add the ‘dhcp4: no’ option and nothing changes (i.e. 169.254 address still exists), change to ‘dhcp4: false’ and all is well now. As usual, working harder not smarter in linux.

Nope, still have a 169.254 address, just couldn’t see it in ‘ifconfig’. Only showed up in ‘ip a’. Irritating.

Gotta love reading through a whole article of bad ideas and bad advice to find that one config line that works around a bug in apt. IPv6 is not the future some years from now, IPv6 was the future years ago. Now, IPv6 is the NOW and should be used as much as possible. The fact that apt will not fall back on using IPv4 if an IPv6 connection failed is a failing in the apt software that is worked around easily with the last small section of this article. Instead of advising people to disable IPv6 on their machines, we should be advising people to use small workarounds like that while the folks who maintain apt sort out their issue (if they even intend to). I also strongly suggest running responsible firewall configs before connecting to things like airport WiFi.

Источник

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