15

I am unable to access my home network from WSL2 subsystem. I have Ubuntu installed in it.

anirban@Desktop:/mnt/g/BASH_WORKSPACE$ lsb_release -a                                                             No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.2 LTS
Release:        18.04
Codename:       bionic
anirban@Desktop:/mnt/g/BASH_WORKSPACE$ uname -r                                                                   4.19.57-microsoft-standard

The eth0 in WSL2 has the following config:

anirban@Desktop:/mnt/g/BASH_WORKSPACE$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.213.230  netmask 255.255.240.0  broadcast 172.20.223.255
        inet6 fe80::215:5dff:fecf:39a5  prefixlen 64  scopeid 0x20<link>
        ether 00:15:5d:cf:39:a5  txqueuelen 1000  (Ethernet)
        RX packets 100  bytes 10544 (10.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 12  bytes 936 (936.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

anirban@Desktop:/mnt/g/BASH_WORKSPACE$ ip addr show                                                               1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 92:ce:02:d5:ab:9b brd ff:ff:ff:ff:ff:ff
3: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether ce:ec:a2:b5:b2:b0 brd ff:ff:ff:ff:ff:ff
4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:15:5d:cf:39:a5 brd ff:ff:ff:ff:ff:ff
    inet 172.20.213.230/20 brd 172.20.223.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::215:5dff:fecf:39a5/64 scope link
       valid_lft forever preferred_lft forever
5: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
    link/sit 0.0.0.0 brd 0.0.0.0

The routes from WSL2 did not have a default route. So, I added in a default route, through eth0.

anirban@Desktop:/mnt/g/BASH_WORKSPACE$ ip route
172.20.208.0/20 dev eth0 proto kernel scope link src 172.20.213.230
anirban@Desktop:/mnt/g/BASH_WORKSPACE$ sudo ip route  add default dev eth0                                        anirban@Desktop:/mnt/g/BASH_WORKSPACE$ ip route                                                                   default dev eth0 scope link
172.20.208.0/20 dev eth0 proto kernel scope link src 172.20.213.230

The vEthernet in Windows has the default config, and surprisingly does not fall within the subnet of the WSL.

PS C:\Users\tukai> ipconfig

Windows IP Configuration


Ethernet adapter Ethernet:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter VirtualBox Host-Only Network #3:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::61be:a6f4:e22d:e985%54
   IPv4 Address. . . . . . . . . . . : 192.168.99.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

Wireless LAN adapter Local Area Connection* 1:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Local Area Connection* 2:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Wi-Fi:

   Connection-specific DNS Suffix  . :
   IPv6 Address. . . . . . . . . . . : 2a02:8108:45c0:263c::67fd
   IPv6 Address. . . . . . . . . . . : 2a02:8108:45c0:263c:a847:a373:36ab:c040
   Temporary IPv6 Address. . . . . . : 2a02:8108:45c0:263c:18a:4a6a:fb9a:3018
   Link-local IPv6 Address . . . . . : fe80::a847:a373:36ab:c040%11
   IPv4 Address. . . . . . . . . . . : 192.168.0.96
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : fe80::f2af:85ff:fea5:c6e6%11
                                       192.168.0.1

Ethernet adapter Bluetooth Network Connection:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter vEthernet (WSL):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::41b:9492:2bea:cf6c%49
   IPv4 Address. . . . . . . . . . . : 172.20.208.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

Anybody has any leads on what the problem could be? Note: My wifi obviously has internet access, and I am trying to ping 8.8.8.8 from WSL2 subsystem to check for internet connectivity. I am using Windows Preview build 10.0.18956

Thanks,

AnirbanMukherjee
  • 379
  • 1
  • 5
  • 14
  • Did you find a solution to this yet? I have been facing the same issue on 1 of my PC's since installing wsl2, however on my other PC, the networking works perfectly and both have the same config, unless I'm missing some tiny details. – Rick Feb 15 '20 at 12:08

7 Answers7

23

I had the same issue and was able to make it work again by running the commands below (I got this from somewhere else, sorry I don't remember where):

In wsl

Fix network issues, Delete auto-generated files

[root@PC-NAME user]# rm /etc/resolv.conf || true
[root@PC-NAME user]# rm /etc/wsl.conf || true

Enable changing /etc/resolv.conf, Enable extended attributes on Windows drives

[root@PC-NAME user]# cat <<EOF > /etc/wsl.conf
[network]
generateResolvConf = false
[automount]
enabled = true
options = "metadata"
mountFsTab = false
EOF

Use google nameservers for DNS resolution

[root@PC-NAME user]# cat <<EOF > /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
EOF

Exit Linux WSL

In Windows, cmd as admin:

wsl --shutdown
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns

Windows Search > Network Reset

Edd
  • 932
  • 10
  • 24
  • 3
    I skipped the last network reset part, but the rest worked anyway. Tested on ubuntu 18.04 and 20.04. – FeatureCreep Dec 27 '20 at 10:08
  • 1
    does not work for Windows Enterprise 1909 OS build 18363.1256 https://github.com/microsoft/WSL/issues/6427 – Edgar Manukyan Jan 14 '21 at 03:53
  • thank you so much for this! i love how it's not a script that needs to be ran after every reboot. works better for me than these two examples https://stackoverflow.com/questions/61002681/connecting-to-wsl2-server-via-local-network and https://www.youtube.com/watch?v=yCK3easuYm4 – L.Le Dec 13 '22 at 10:54
4

I was looking for info about this earlier today, and came across a really well-written gist which has the exact instructions you need - https://gist.github.com/pyther/b7c03579a5ea55fe431561b502ec1ba8

It includes instructions on how to make these networking changes whenever you connect to or disconnect from your VPN.

James McPherson
  • 2,476
  • 1
  • 12
  • 16
3

It took me a few days to find an answer to a similar problem... :-/ All kudos to this guy: https://github.com/microsoft/WSL/issues/5286#issuecomment-638739724

After I've done all the things about /etc/resolv.conf it was still not working, so my issue was about compression I turned on on a laptop drive.

The fix is to uncompress temp folder (in addition to the folder with WSL packages):

wsl --shutdown
compact /u %TEMP% /i /Q
c-tran
  • 71
  • 4
3

This solved it 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
midi
  • 3,128
  • 5
  • 30
  • 47
1

Best I can do is provide a working example. Note that in my config, the WSL2 adapter (eth0) is on a different subnet from the default gateway, but it will still use the default when the interface has no override. The gateway IP is a virtual tap interface that's provided by the windows host. So it needs to match the IP given to the vEthernet (WSL) interface of the windows host.

WSL2 Bash:

$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.31.121.217  netmask 255.255.240.0  broadcast 172.31.127.255
        inet6 fe80::215:5dff:fe1c:7078  prefixlen 64  scopeid 0x20<link>
        ether 00:15:5d:1c:70:78  txqueuelen 1000  (Ethernet)
        RX packets 247038  bytes 264215849 (264.2 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 81867  bytes 5902917 (5.9 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


$ ip route
default via 172.31.112.1 dev eth0
172.31.112.0/20 dev eth0 proto kernel scope link src 172.31.121.217

From the host (cmd.exe)

Ethernet adapter vEthernet (WSL):

   Connection-specific DNS Suffix  . : 
   IPv4 Address. . . . . . . . . . . : 172.31.112.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

In your routing table, you added a default gateway to a subnet, instead of a specific IP. Try changing it to match the vEthernet interface:

172.20.208.1

But I would be concerned about messing with the WSL2 networking, in case something changes between now and the final release candidate. I would consider installing a new image and moving your files across. Alternatively, you can use cygwin as a Bash file system for storing files that you want accessible to WSL. This will protect you from munged WSL images, which you may have suffered, depending on how long you've been part of the preview. If you go this route, this should help, https://medium.com/@rcoe67/tips-for-seamlessly-using-cygwin-and-wsl-in-windows-10-9ed1a72ace6c

Robin Coe
  • 750
  • 7
  • 28
1

When you connect to Cisco Anyconnect WSL2 will NAT to the highest priority Ethernet Adapter. A newer version of Cisco Anyconnect from the Windows Store seems to correct this; however, it doesn't support Dual Factor Authentication. So to correct this I use the following script for PowerShell.

Steps:

  • Restart Computer (or begin from fresh start) Login to Computer,
  • Connect via Cisco AnyConnect Run a script from Powershell that includes the follow (Note: your adapter name may need to be changed on Line 2 in quotes)
Get-NetIPInterface -InterfaceAlias "vEthernet (WSL)" | Set-NetIPInterface -InterfaceMetric 1
$VPNInterfaceName = "Ethernet 3"
Get-NetIPInterface -InterfaceAlias $VPNInterfaceName | Set-NetIPInterface -InterfaceMetric 5001

Once that's been completed open WSL and you should be good to go, unless there is something else causing further issues that I had not experienced. I hope this helps, as we spent several days attempting to track down the cause.

Edit: Be sure if you have "Ubunut/WSL" set as your default profile in Windows Terminal, that you run the script prior to starting WSL. So if Ubuntu/WSL is your default, set your default to PowerShell, or switch over to PowerShell, run the command wsl --shutdown, then execute the above script, then reopen Ubuntu/WSL.

daveomcd
  • 6,367
  • 14
  • 83
  • 137
0

https://learn.microsoft.com/en-us/windows/wsl/install-manual#step-2---check-requirements-for-running-wsl-2

cmd run as admin
wsl --shutdown
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
wsl --set-default-version 2

then , you can start wsl

miah
  • 10,093
  • 3
  • 21
  • 32
user3073309
  • 184
  • 2
  • 5