Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Very slow network speed on WSL2 #4901

Open
carl-berg opened this issue Feb 16, 2020 · 388 comments
Open

Very slow network speed on WSL2 #4901

carl-berg opened this issue Feb 16, 2020 · 388 comments
Labels

Comments

@carl-berg
Copy link

carl-berg commented Feb 16, 2020

Windows build number: 10.0.19041.84
Dist: Ubuntu 18.04 LTS

I just installed WSL2 on my home computer for the first time and something i notice that i don't see on my work computer is that WSL2 has dramatically lower network speed (wget or git clone tested). Speeds on WSL seem to be about 10-20 kb/s wheras windows download speed seem to be correlating to my ISP spec of 100/10 Mbps or above.

@therealkenc
Copy link
Collaborator

Screencap speedtest-cli as a starting point.

$ sudo apt install speedtest-cli
$ speedtest-cli
[...]

image

@carl-berg
Copy link
Author

Okies, here's speedtest on windows, in the browser:
Speedtest_win

...and here's speedtest from wsl2:
Wpeedtest_wsl2

@acirulis
Copy link

Same here. Especially upload speed was drastically reduced - 36.61 -> 3.85 Mbit/s

@guilhermehrcosta
Copy link

Hi, same here. My download was drastrically reduced of 200Mbit/s to 2 Mbit/s. Is there a solution?

@AndrewGaspar
Copy link

I'm hitting this issue, as well. Very frustrating.

@kennethnipper
Copy link

I'm seeing same issue. Speedtest-cli in bash:
image

speedtest in Windows:
image

@tin-liu
Copy link

tin-liu commented Mar 14, 2020

Edit: After several reboots and adding the related folders as exceptions in Windows Defender as @jituanlin 's referred blog pointed out, and then tried removing the exceptions because I wanted to check which folder exception actually helped (so eventually theoretically equivalent to reboots-only, but who knows?), now in WSL Ubuntu Ver. 2 I have down = ~80 Mbit/s & up = ~4 Mbit/s. The upload is still about only 1/10 of the actual limit, but the download is up-to-standard now.

Also, the command speedtest is ~15 Mbit/s faster (download) than speedtest-cli for me.

Old comment:
Windows network faster than WSL Ubuntu Ver. 1 which faster than WSL Ubuntu Ver. 2 here:

  1. Windows Ookla on Web browser
    down ~88 Mbit/s
    up ~38 Mbit/s
  2. WSL Ubuntu Ver. 1 speedtest-cli
    down ~32 Mbit/s
    up ~4 Mbit/s
  3. WSL Ubuntu Ver. 2 speedtest-cli
    down ~3 Mbit/s
    up ~4 Mbit/s

Cheers

@jituanlin
Copy link

After follow this blog
My network/file access improve more than 5 times speed.

@rducom
Copy link

rducom commented Apr 8, 2020

Same here, really annoying. Disabling AV (defender) doesn't helps
image

@markgaze
Copy link

markgaze commented May 3, 2020

Same here. Getting about 7Mbit/s on WSL2 and 30+ in Windows.

Disabling Defender also made no difference for me either.

@Vildevil
Copy link

Vildevil commented May 15, 2020

Same here :
Windows and WSL :

  • Up 261mb/s
  • Down 248mb/s

WSL 2 :

  • Up 1.60mb/s
  • Down 0.08mb/s

@copeland3300
Copy link

copeland3300 commented May 15, 2020

Oddly, I'm getting decent results from the speedtest-cli, but things such as apt update are extremely slow, that is, less than a MB/s, where I'm used to seeing 30-40MB/s on my standard Ubuntu systems...

Speedtest results...

Retrieving speedtest.net configuration...
Testing from Verizon Fios (108.28.56.14)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by QTS Data Centers (Dulles, VA) [5.59 km]: 27.576 ms
Testing download speed................................................................................
Download: 427.07 Mbit/s
Testing upload speed......................................................................................................
Upload: 85.70 Mbit/s

apt update results

Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [107 kB]
Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease
Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [107 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease [98.3 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [94.0 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [30.5 kB]
Fetched 437 kB in 2s (197 kB/s)

@oliver-dungey
Copy link

Same issue here, dire network speed in WSL2. Performance with Linux or WSL is fine.

@aleled
Copy link

aleled commented May 30, 2020

I am experiencing the same

Speedteswt from WSL are poor compared to CMD

1

@mrorat
Copy link

mrorat commented May 30, 2020

Same here, Windows is about 60Mbps vs WSL2 14kbps !!!!

@arthurgeron
Copy link

I think it's useful to let people know that this doesn't happen to everyone, I'm getting my full speed here in WSL 2 on Windows 10 2004 (non Insider)
image

@didinele
Copy link

didinele commented Jun 2, 2020

Much more interesting for me!

On windows image

Over on my freshly intalled WSL2 image

Seems like download speed remained rather intact, however upload was heavily hit.

Windows 10 Enterprise version 2004, Ubuntu 18.04 LTS`

@rarora7777
Copy link

rarora7777 commented Jun 3, 2020

I'm seeing 249.94mbps down / 15.42mpbs up on Windows, which is pretty much what I expect from my ISP. On WSL2, sppedtest-cli shows 4.69mbps down / 3.29mbps up.

But apt and git performance in WSL2 is so much worse. I'm getting download speeds of 4–16 kbps on both.

I don't recall measuring network speed on WSL1, but such terrible performance would have been quickly noticed.
Edit: Just installed a WSL1 Ubuntu 20.04 LTS and I got 193.61 mbps down / 16.94 mbps up.

I'm on Windows 10 Enterprise version 2004 (build 19041.264) and Ubuntu 18.04 LTS that I recently upgraded to WSL2.

@BeErikk
Copy link

BeErikk commented Jun 4, 2020

Just FYI. I have experienced extremely slow network speed as well, but it seems to be a temporary issue. Perhaps a local network issue? Right now in WSL 1 (2004 not insider) I get:

speedtest-cli
Retrieving speedtest.net configuration...
Testing from AllTele (XX.XX.XX.XXX)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by A3 Allmänna IT - och Telekomaktiebolaget (Stockholm) [162.45 km]: 12.928 ms
Testing download speed................................................................................
Download: 124.83 Mbit/s
Testing upload speed......................................................................................................
Upload: 122.34 Mbit/s

@JennToo
Copy link

JennToo commented Jun 5, 2020

I was having a similar issue and found that switching from Wifi to Ethernet helped.
I don't really understand why, as speedtests over my Wifi are fine outside of WSL2. I suppose it's possible that the Ethernet driver is somehow interacting with WSL and/or HyperV better.

Ethernet NIC is a "Killer E2500 Gigabit"
WiFi is a "Killer Wireless n/a/ac 1535" (though the only thing it seemed to "Kill" was my network performance 😄)

@dvsmaxv
Copy link

dvsmaxv commented Jun 9, 2020

Hello friends,
I'm not good at English, But me too I faced the same issue and I tried so many time and finally I got one solution and here's the url: https://www.hitxp.com/articles/software/ubuntu-fix-slow-wireless-internet-connection-speed-upgrading-11-04-natty-narwhal/. With sample pic

Screenshot from 2020-06-09 22-05-31

@matze19999
Copy link

don't have the problem on surface pro x (arm64)

@mrorat
Copy link

mrorat commented Jun 10, 2020

It gets better... my speedtest today (Ethernet):
WSL2:
Download: 45.98 Mbit/s
Upload: 3.39 Mbit/s

Windows:
Download: 46.5 Mbit/s
Upload: 17.8 Mbit/s

@takizo
Copy link

takizo commented Jun 10, 2020

Hi all, I got the latest Windows 10 ver 2004 update. Switching from WSL1 to WSL2. I have the similar slow issue like you all had. But not particularly on the internet, it's more on Windows to Ubuntu via localhost access

Windows Version: 2004
Build: 19041.264
Ubuntu: 18.04.4

I run php development in WSL with Ubuntu 18.04.4, I have apache2, php7.2 and MariaDB running very well on WSL1

During development, I usually tunnel to my server to load ElasticSearch/Postgresql data, the tunnel is listen on localhost with respective port numbers.

I do not have connection problem when running in WSL1, the speed is tremendous fast. It's fast like the data is loading on my machine itself.

But when I switch to WSL2, I notice the connection is extremely slow. The initial loading took like 5-7 secs. Then the page would rendered. The hostname is mapped to 127.0.0.1, I've tried mapped on WSL2 Ubuntu private IP, the results are the same - Slow.

I've capture the video and sharing with you all.

Here is the video running on WSL1

https://www.youtube.com/watch?v=tNFtUUd2sG4

What I did was wsl --set-version Ubuntu 2, to upgrade the current Ubuntu distro to WSL2. Here is the video of the same development site running on WSL 2 (Please look at left bottom status bar)

https://www.youtube.com/watch?v=JFYgzMHf2RU

I've tried the comments on this thread, no luck getting it load fast like WSL 1. Hopefully this can be fixed,

I've switched back to WSL1 and the speed is back to normal. You may refer to the video below, the result is instance.

https://www.youtube.com/watch?v=9Q5Ors94lJM

@ericblade
Copy link

Interestingly -- GUI apps (at least, google-chrome) don't seem to be restricted. google-chrome I can hit 1.1gbps at fast dot com. at speedtest dot net, 900mbps. through speedtest-cli, max 250-300mbps.

Make it make sense, please. :D

@pkgears
Copy link

pkgears commented Feb 20, 2024

I had the same very frustrating problem but i think i got a work around. I used https://github.com/ChrisTitusTech/winutil to reset Winsock (Reset Networking). It is under Config > Reset Network. I am not 100% sure if it was this alone because i also completly removed WSL and Hypervisor from features list and reinstalled it also with this tool. But after this clean up and reinstall and a good old' reboot, everything worked magically. I also did wsl --update immediatly after reboot.

Maybe it helps someone!

This worked for me

@kaziabidazad
Copy link

Tange

This should be the accepted answer.
And why is it not the default value?

@ericblade
Copy link

Tange

This should be the accepted answer. And why is it not the default value?

.... because if resetting the nameserver works for you, then probably your dns is misconfigured in windows. but also, dns is irrelevant to this problem.

@pacorreia
Copy link

About this issue, I faced it as well when using the mirrored mode, but not when using NAT.

So why in my case?
I disabled the automatic update of resolv.conf because wanted to set my own dns servers (on NAT mode), and also to solve VPN issues.

Then mirrored mode came into place, and damn, was weird, but after while it made, mirrored is supposed to share the same IP/interface, meaning also same DNS, but I was using a static config and preventing WSL from automatically updating it.

I've tested setting my nameserver to my local router, and worked like a charm and as expected.
Then reset the resolv.conf file, allowed the automatic updating, and it also worked.

So to wrap up, to add to the checklist, verify if:

  • You've disabled automatic update of /tc/resolv.conf (edit your /etc/wsl.conf), and enable and restart wsl
  • You're using a nameserver poiting to the internal NAT gateway (from you were using NAT mode) and update it to google or the one in your local network

Hope it helps other lost souls out there

@awcator
Copy link

awcator commented Mar 21, 2024

If you have bridged connections with the WSL adapter and your WIFI adapter, it will also slow down. I had to delete the bridge adapter.

@ericblade
Copy link

so... i think we might have a flaw in speedtest apps. Speedtest cli consistently gets 300mbps or less for me, while speedtest in browser consistently is punching 900mbps now.

Also, Docker Desktop has an absolute speedcap of 100mbps, it seems.

@falexbr
Copy link

falexbr commented Mar 29, 2024

I had very slow upload speeds on WSL2 and figured out that my problem was with my wifi adapter being used as an External Network on Hyper-V Virtual Switches. I just deleted the switch and got full upload speed again.

@micksatana
Copy link

micksatana commented May 1, 2024

I previously have the experimental mirrored networking mode on as well, but it still require to have the Real-time protection disabled to be fast. Appends this into C:\Users\YOURNAME\.wslconfig

[experimental]
networkingMode=mirrored

Temporary disable Windows Defender > Virus & threat protection > Manage settings > Real-time protection works for me. The speed goes up rights away.

More permanent solution would be setting up Dev Drive and have WSL2 on Dev Drive (I don't know how to do that at the moment), probably need to wait for microsoft/devhome#748

@s0kil
Copy link

s0kil commented May 4, 2024

Just for people still looking for a complete solution

Create this file in C:\Users\YOURUSER\.wslconfig

[wsl2]

[experimental]
networkingMode=mirrored

And run wsl --shutdown in your terminal

Thats it, when you re-start your WSL distro, it should have the same speed as your Windows host

Read more about this here: https://learn.microsoft.com/en-us/windows/wsl/wsl-config#wslconfig

This also fixed slow WSL2 downloads for me.

@ericblade
Copy link

ericblade commented May 5, 2024

Since the latest WSL2 update, I'm pulling in 400-500mbps pretty consistently. However, in Windows, I'm pulling 2Gbps. I'm also no longer throttled to 100mbps total in docker-desktop

@geraldoam
Copy link

Just for people still looking for a complete solution

Create this file in C:\Users\YOURUSER\.wslconfig

[wsl2]

[experimental]
networkingMode=mirrored

And run wsl --shutdown in your terminal

Thats it, when you re-start your WSL distro, it should have the same speed as your Windows host

Read more about this here: https://learn.microsoft.com/en-us/windows/wsl/wsl-config#wslconfig

this one work for me, thank u

@neongoblin69
Copy link

Just for people still looking for a complete solution

Create this file in C:\Users\YOURUSER\.wslconfig

[wsl2]

[experimental]
networkingMode=mirrored

And run wsl --shutdown in your terminal

Thats it, when you re-start your WSL distro, it should have the same speed as your Windows host

Read more about this here: https://learn.microsoft.com/en-us/windows/wsl/wsl-config#wslconfig

Thank you very much, it helped. One question though, how did you find it ? Is it mentioned in docs or smth ?

@joaolucaswork
Copy link

After follow this blog My network/file access improve more than 5 times speed.

This works well for me.

@hitzhangjie
Copy link

hitzhangjie commented May 29, 2024

I see this problem, too. None of the suggestions mentioned above directly solves my problem, but it give me a right direction. In my case, my PC is installed an enterprise IT management software, it installed a virtual network adaptor, which supports higher network throughput than windows provided default, but it doesn't work well with WSL. So I just disable the feature, then problem solved.

@televators
Copy link

Tangentially related: it was taking my WSL really long to reach any DNS server, so I changed /etc/resolv.conf's value to 8.8.8.8 which massively sped up how long it took to find links. Hope this helps some of you.

Worked for me as well. Notice for future people edit it with nano under sudo nano /etc/resolv.conf also here line you need to add nameserver 8.8.8.8 and comment other one with namespace

Holy $#*!
I've wrestled with this issue for so long and could never get any improvement. Just updated this on mine and my WSL2 speedtest went from 0.1Mbps to 15Mbps, with ping under 50ms. The biggest issue for me has been the latency. Doing anything from WSL2 had a consistent latency of like 10–60 seconds, and my local dev projects would be impossible to use correctly since basically any API calls timed out 100% of the time.

I had updated host to use 1.1.1.1 but saw no difference. Didn't think about updating the DNS for Ubuntu itself, as I subconsciously presumed it would use the host's config for some reason.
Thank you thank you thank you.

PSA: Just editing /etc/resolv.conf won't last since it usually gets overwritten on reboot, so you'll need to look into the proper way to permanently set your DNS depending on what distro and network manager and all that jazz.

@BonScottCH
Copy link

BonScottCH commented Jul 25, 2024

I was able to solve the issue on my WSL (opensuse) by editing the /etc/resolv.conf file. I replaced the default nameserever with 8.8.8.8 and it fixed my issues.

As you can see after updating /etc/resolv.conf the speed increased

image

I don't really get why it spped up the troughput besides the lookup time, but i'm not sure how speedtest works under the hood.

@ericblade
Copy link

Since 2.3.12, i am pulling 500mbps on command line linux apps, and upwards of 2.0gbps on X11 apps. Makes no sense. Both using the same speedtest servers. But it's much faster than the 100mbps cap that I had in previous versions.

Still capped to 100mbps or less in Docker based WSL apps though

@ahmvdev
Copy link

ahmvdev commented Jul 31, 2024

this worked for me:

sudo rm /etc/resolv.conf
sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "[network]" > /etc/wsl.conf'
sudo bash -c 'echo "generateResolvConf = false" >> /etc/wsl.conf'
sudo chattr +i /etc/resolv.conf

works after reboot aswell, since its permanent changes

@starkgate
Copy link

gets better... my speedtest today (Ethernet): WSL2: Download: 45.98 Mbit/s Upload: 3.39 Mbit/s
Windows: Download: 46.5 Mbit/s Upload: 17.8 Mbit/s

netsh int ipv4 set interface "Wi-Fi" forwarding=enable

What is this magic? It fixed the awfully slow WSL 2 network connection.

it fixed the super slow speed on Firefox on WSL2 for me! I'm using an external Wi-Fi adapter

This works for me, too. To be specific:

1. in a Windows terminal, I used `ipconfig` to find the interface name of my WIFI adapter. "Wi-Fi 2" in my case.

2. In a windows terminal I ran with the administrator privilege, I typed the command
   `netsh int ipv4 set interface "Wi-Fi 2" forwarding=enable`. The response is `OK.`.

The download speed immediately improves in my WSL2 Ubuntu 22. I think the issue is probably with my using Wi-Fi, which is not properly forwarded to the container.

This worked for me, thanks! In my case I was connected via cable so the adapter name was "Ethernet".

@puzzle9
Copy link

puzzle9 commented Aug 26, 2024

When using NAT mode
using 127.0.0.1 is normal
using wsl ip is very slow

When using mirrored mode
using 127.0.0.1 is very slow

nat mode test

in wsl

cd /dev/shm/
dd if=/dev/zero of=file bs=1M count=500
python3 -m http.server 3000

in win

wget http://127.0.0.1:3000/file -O NUL
--2024-08-26 21:17:51--  http://127.0.0.1:3000/file
Connecting to 127.0.0.1:3000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 524288000 (500M) [application/octet-stream]
Saving to: 'NUL'

NUL                           100%[=================================================>] 500.00M   937MB/s    in 0.5s

2024-08-26 21:17:51 (937 MB/s) - 'NUL' saved [524288000/524288000]

wget http://172.27.83.126:3000/file -O NUL
--2024-08-26 21:18:08--  http://172.27.83.126:3000/file
Connecting to 172.27.83.126:3000... connected.
HTTP request sent, awaiting response... 200 OK
Length: 524288000 (500M) [application/octet-stream]
Saving to: 'NUL'

NUL                             0%[                                                  ]   2.84M   403KB/s    eta 20m 1s

After reinstalling the system, the speed returned to normal

@dahvo
Copy link

dahvo commented Sep 1, 2024

netsh int ipv4 set interface "Wi-Fi" forwarding=enable

What is this magic? It fixed the awfully slow WSL 2 network connection.

it fixed the super slow speed on Firefox on WSL2 for me! I'm using an external Wi-Fi adapter

This worked for me

That immediately fixed it for me too.

This worked for me too, just made sure to set it for the correct adapter which in my case was "Wi-Fi"

@Anonymo
Copy link

Anonymo commented Sep 1, 2024

If you're experiencing slow download speeds in WSL2, you can add custom DNS servers to the /etc/resolv.conf file while preserving the existing localhost entry. Follow the steps below:

Step 1: Disable Automatic resolv.conf Generation

  1. Open your WSL2 terminal.
  2. Edit the WSL configuration file by running:
    sudo nano /etc/wsl.conf
  3. Add the following lines to prevent automatic overwriting of /etc/resolv.conf:
    [network]
    generateResolvConf = false
  4. Save and exit the editor.

Step 2: Edit the Existing resolv.conf File to Add Custom Nameservers

  1. Open the existing resolv.conf file for editing:

    sudo nano /etc/resolv.conf
  2. Add your preferred DNS servers below the existing localhost entry. For example, to add Google’s DNS servers, you would include:

    nameserver 127.0.0.1
    nameserver 8.8.8.8
    nameserver 8.8.4.4
    

    This keeps the localhost entry intact while adding additional nameservers.

  3. Save and exit the editor.

Step 3: Restart WSL2

  1. Shut down WSL2 to apply the changes by running:
    wsl --shutdown
  2. Restart your WSL2 instance by opening your desired Linux distribution.

Outcome:

After following these steps, your WSL2 instance will use the specified custom DNS servers in addition to the default localhost entry. This should help resolve slow download speed issues without removing the existing resolv.conf file or the localhost entry.

@ericblade
Copy link

speed test from windows: 1.5gbps
speed test from x11 google-chrome: 1.5gbps
speed test from cli speedtest app: 600mbps
speed test from wsl2 docker host: 400mbps
speed test from wsl2 with vpn: 60mbps
speed test from windows with vpn: 600mbps

make it make sense please

@classicrocker883
Copy link

This works for me, too. To be specific:

1. in a Windows terminal, I used `ipconfig` to find the interface name of my WIFI adapter. "Wi-Fi 2" in my case.

2. In a windows terminal I ran with the administrator privilege, I typed the command
   `netsh int ipv4 set interface "Wi-Fi 2" forwarding=enable`. The response is `OK.`.

This has also improved my download speed.

@A6blpka
Copy link

A6blpka commented Oct 29, 2024

.wslconfig

[wsl2]
dnsTunneling=false

Raised the speed from 1mbps to 80mbps, and random timeouts to DNS are gone.

@rishabhnehra
Copy link

Another thing I found is this issue reproducible when I'm connected to WiFi. On Ethernet/USB Hotspot, the speed is similar in both WSL and Windows. My work laptop has the issue, but I thought that could be because of security applications pre-installed, so they must be interfering with WSL. Turns out that using Ethernet works flawless. Maybe something wrong with WiFi and WSL network bridge driver. Not sure.

@h3llmo
Copy link

h3llmo commented Nov 10, 2024

.wslconfig

[wsl2]
dnsTunneling=false

Raised the speed from 1mbps to 80mbps, and random timeouts to DNS are gone.

Unfortunately, it changed nothing on my side...

@khasizadaj
Copy link

If you're experiencing slow download speeds in WSL2, you can add custom DNS servers to the /etc/resolv.conf file while preserving the existing localhost entry. Follow the steps below:

Step 1: Disable Automatic resolv.conf Generation

...

Step 2: Edit the Existing resolv.conf File to Add Custom Nameservers

....

Step 3: Restart WSL2

....

Outcome:

After following these steps, your WSL2 instance will use the specified custom DNS servers in addition to the default localhost entry. This should help resolve slow download speed issues without removing the existing resolv.conf file or the localhost entry.

This worked for me. One other thing I'd add is to change permissions of /etc/resolv.conf to Read/Execute (i.e. 555). Otherwise it will be overwritten. /etc/wsl.conf update should have stopped this behavior, but it was the case for me.

sudo chmod 555 /etc/resolv.conf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests