# 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

• The update-grub command is in the package grub2-common, and generally I make changes to /etc/default/grub. In a straight Ubuntu installation, I don't seem to have the directory that you specify for grub. Sep 24, 2017 at 13:28
• There's no point to GRUB or doing core network related changes - booting and networking are in the hands of Windows. As for the config file, there's no reason for it to not exist; the files come from the unmodified Ubuntu packages that WSL uses.
– muru
Sep 24, 2017 at 13:41
• Echoing what @muru says there is no point in using grub anymore for dual booting. Indeed you can quadruple use Windows, Ubuntu, Suse and Fedora concurrently with low disk and memory requirements because not needing VM. Historically you would figuratively "bash on windows" but now you can literally run "bash on windows". Oct 7, 2017 at 23:27
• I also got the cannot stat error when running sudo sysctl -p, but it seemed to work anyway. At least, apt is not throwing IPv6 errors anymore. Edit: Yes it is, sometimes. Still looking for a solid fix. Mar 9, 2018 at 17:32
• @muru Could you add that as answer? This question is getting flagged as "off-topic" but it's not really off-topic if the answer is "it's not possible". Mar 9, 2018 at 21:18

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.

1. Edit the /etc/gai.conf
$sudo vi /etc/gai.conf  1. 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  • Amazing, I had no idea this file even exist ! What stands for gai ?? Apr 24, 2020 at 22:29 • @Stéphane Get Address Information – Yvon Jun 4, 2021 at 0:08 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. 1. Control Panel > Network and Sharing Center > Change adapter settings or Win+R ncpa.cpl Enter 2. On your adapter (e.g. Ethernet), right-click > Properties or double-click > Properties or Alt+Enter or Change settings of this connection 3. Uncheck Internet Protocol Version 6 (TCP/IPv6) 4. OK 5. 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. • Can you give instructions on how to disable IPv6? Mar 8, 2018 at 23:46 • @stumblebee Instructions added. It would be really nice to have a way to do it just in WSL, though. Mar 9, 2018 at 20:29 • I have IPv6 disabled on windows because I don't have IPv6 with my ISP, but WSL still has an inet6 (IPv6) loopback interface, which I believe is preventing certain domains from resolving properly for me. The URLs, sh.rustup.rs and static.rust-lang.org (for installing rust build tools), wont resolve in WSL unless I use -4 flag in curl or wget. Jan 5, 2020 at 23:54 • Something in Windows keeps enabling it each time WSL is running. Apr 21, 2020 at 17:42 • this fixed npm install under WSL2 - stackoverflow.com/a/72564257/555451 Jun 9 at 17:36 If you are using WSL2 you have the thermonuclear option of building your own kernel without IPv6 support. The source code of WSL2 kernel as well as the instructions for building it are available on GitHub. To save you some time here are the instructions: sudo apt install build-essential flex bison libssl-dev libelf-dev git dwarves python3 bc git clone https://github.com/microsoft/WSL2-Linux-Kernel.git cd WSL2-Linux-Kernel/ cp Microsoft/config-wsl .config  now open .config, find line CONFIG_IPV6=y and change y to n. build your kernel: make -j$(nproc)


to install your kernel you'll need copy it to a directory outside of your WSL2 VM and then create file .wslconfig in your Windows home directory with the following contents:

[wsl2]
kernel=C:\\Path\\to\\your\\kernel


Mind the double backslashes. Obviously you'll need to replace the placeholder above with the actual path.