Thanks for reposting this from Stack Overflow. As I implied on my comment on that original question, I think there are two issues/questions going on here:
- The main one is that you don't have Internet access, of course.
- Secondary is that you are trying to use the
networkctl
command under WSL, which won't work.
Let's start with the second one. As I mentioned in my comment, networkctl
won't work for the reason that's mentioned in my answer here. That is:
systemd-networkd is not running, output will be incomplete.
That tells you that this (the networkctl
issue) is Systemd-related. As noted in that answer, Systemd isn't supported on WSL without additional effort (that I tend to not recommend).
So as with systemctl
, you need other alternatives. For instance, the ip
command:
ip link
(or ip link show
) will show you the status of the network devices.
ip addr
/ip address
will show you the IP addresses in use on those devices.
That said, with networking on WSL2, there's often not much that you can do internally (in Ubuntu) to fix it (or even diagnose the issue). I'll be honest, resolving networking issues under WSL2 can be difficult, but we'll try ...
Just as a preface, WSL2 networking is provided by either:
- The "Virtual Machine Platform" feature (typically)
- Or, alternatively, the Hyper-V manager (on Windows Pro or higher)
Both are essentially the same core Windows code, but the VMP is a scaled down version that runs on Windows Home so that you can use WSL2 there (since Hyper-V isn't available on Home).
WSL2 sets up a virtual Hyper-V network switch that sits "between" the WSL2 network and the Windows "real" network. The WSL2 instance normally is NAT'd behind that virtual switch.
So when you face issues with networking in WSL just not working, it's typically because of some failure of the virtual switch to communicate with the host.
Some of the more common causes:
If Windows is connected to a VPN, the VPN software will often block other local connections. Since WSL2 is a separate local network location, it cannot operate when connected to the VPN.
If this is the case for you, the answer may be dependent on your actual VPN. One workaround or solution for Cisco AnyConnect, at least, appears to be to increase the interface metric for the VPN adapter so that (I believe) local connections take priority.
The WSL2 network switch is also susceptible to problems in the swap file, for some reason. Sometimes see my Stack Overflow answer on that topic. Disabling swap (via %userprofile%\.wslconfig
) has solved WSL2 networking problems for a number of users.
Occasionally, there have been Microsoft patches that corporate IT has pushed to systems that have caused the WSL2 network to break. Usually, that's indicated by it working previously but then no longer working spontaneously.
And there are a number of other troubleshooting steps you can try. Some great ones are listed at the bottom of the same SO question (in the things already tried), but there are some additional answers there to try as well.