Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to access network from WSL2

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,

like image 209
AnirbanMukherjee Avatar asked Aug 23 '19 21:08

AnirbanMukherjee


People also ask

How do I access Internet from WSL2?

Under the "Advanced network settings" section, click the Network reset option. Click the Reset now button. Click the Yes button. After you complete the steps, the computer will restart automatically, and on reboot, you should now be able to connect to the internet.

Can WSL access local network?

When using a WSL 1 distribution, if your computer was set up to be accessed by your LAN, then applications run in WSL could be accessed on your LAN as well. This isn't the default case in WSL 2. WSL 2 has a virtualized ethernet adapter with its own unique IP address.


1 Answers

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

like image 50
Edd Avatar answered Oct 25 '22 22:10

Edd