- How to disable or enable ipv6 in Linux
- Disable IPv6 for the complete node (for all interfaces)
- Enable IPv6 on RHEL
- 2 Ways to Disable IPv6 on Ubuntu Desktop & Server
- Method 1: Disable IPv6 on Ubuntu via GRUB Boot Loader
- Method 2: Disable IPv6 on Ubuntu via sysctl
- Disable IPv6 in Netplan
- Disable IPv6 in NetworkManager
- Disable IPv6 in APT
- 16 Responses to “2 Ways to Disable IPv6 on Ubuntu Desktop & Server”
How to disable or enable ipv6 in Linux
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
You cannot enable IPv6 for a particular interface unless your node has IPv6 enabled via GRUB i.e. if you have disabled ipv6 using grub then a single interface cannot be configured for ipv6.
If you attempt for this then you might end up with error similar to below
# sysctl -p
kernel.shmmax = 18446744073692774399
kernel.shmall = 18446744073692774399
kernel.randomize_va_space = 0
kernel.core_pattern = /var/opt/sdf/cores/core.%e
sysctl: cannot stat /proc/sys/net/ipv6/conf/eth0/disable_ipv6: No such file or directory
So first step would be to enable ipv6 from GRUB
Delete the entry «ipv6.disable=1» from «GRUB_CMDLINE_LINUX» variable in /etc/default/grub
# grep » GRUB_CMDLINE_LINUX » /etc/default/grub
GRUB_CMDLINE_LINUX color: #111111;»>/proc/sys/net/ipv6/conf/all/disable_ipv6=1
/proc/sys/net/ipv6/conf/default/disable_ipv6
/proc/sys/net/ipv6/conf/ /disable_ipv6
Un-comment the below line from /etc/hosts file
::1 localhost ipv6-localhost ipv6-loopback
Check the content of the file /etc/ssh/sshd_config and make sure the AddressFamily line is commented:
# AddressFamily inet
Lastly reboot the system to activate these changes
I hope the article was useful.
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.
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.
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"
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
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.
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.
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.
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.