How to disable IPv6 on Windows Subsystem for Linux?
I tried to disable IPv6 by adding in /etc/sysctl.conf
:
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
and then running sudo sysctl -p
to reload the /etc/sysctl.conf
settings - but that threw the error:
sysctl: cannot stat /proc/sys/net/ipv6/conf/all/disable_ipv6: No such file or directory
I tried to also disable it by changing grub configuration /etc/default/grub.d/50-cloudimg-settings.cfg
to:
GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 console=tty1 console=ttyS0"
and then run sudo update-grub
but there is no update-grub installed:
sudo: update-grub: command not found
So I am not sure if it is even possible to update grub, but the fact there is a specific configuration located there makes me thing there is.
WSL version:
Description: Ubuntu 16.04.2 LTS
Release: 16.04
Codename: xenial
Solution 1:
Instead of disabling IPv6 completely, you can instruct Ubuntu to prefer IPv4 connections to IPv6 by editing the precedence blocks in /etc/gai.conf
.
Using this solution:
- You may access servers in Internet with IPv4 an IPv6 servers through a NAT or a router that only understand IPv4
- Use IPv4 and IPv6 in the local network
- Avoid errors, for instance, installing gem files from rubygems.org
Preferring IPv4 over IPV6 addresses
Modifying the precedences in the gai.conf
, every time a program calls getaddrinfo()
for resolving host names, Linux will prefer the IPv4 addreses. This is very useful when you try to contact a server with both IPv4 and IPv6 addresses from a machine behind a NAT or a router. In addition, you may use IPv6 locally.
- Edit the
/etc/gai.conf
$ sudo vi /etc/gai.conf
- Uncomment the last lines. Check that file has the next uncommented lines.
#For sites which prefer IPv4 connections change the last line to
precedence ::ffff:0:0/96 100
...
# For sites which use site-local IPv4 addresses behind NAT there is
# the problem that even if IPv4 addresses are preferred they do not
# have the same scope and are therefore not sorted first. To change
# this use only these rules:
#
scopev4 ::ffff:169.254.0.0/112 2
scopev4 ::ffff:127.0.0.0/104 2
scopev4 ::ffff:0.0.0.0/96 14
Solution 2:
I disabled IPv6 in the Windows network adapter properties and that took care of the problem for me. My Ubuntu subsytem started using IPv4 instead.
-
Control Panel > Network and Sharing Center > Change adapter settings
or Win+Rncpa.cpl
Enter - On your adapter (e.g. Ethernet), right-click > Properties
or double-click > Properties
or Alt+Enter
or Change settings of this connection - Uncheck Internet Protocol Version 6 (TCP/IPv6)
- OK
- Repeat as necessary for other adapters, like WiFi
Note that this will disable IPv6 for all of Windows (when using that adapter), not just WSL.