我在Windows计算机的WSL中执行az login
。然后给出一个错误:
Please ensure you have network connection. Error detail: HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url: /common/oauth2/token (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f401d135630>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))
我希望这是DNS问题。
因此,我检查了WSL的/etc/resolv.conf
:
# This file was automatically generated by WSL. To stop automatic generation of this file, remove this line.
nameserver 192.168.1.1
nameserver fcc0:0:0:ffff::1
nameserver fcc0:0:0:ffff::2
192.168.1.1是默认网关。
有一些我尝试过的命令的结果:
$ ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=128 time=0.351 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=128 time=0.888 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=128 time=0.883 ms
$ dig 192.168.1.1
; <<>> DiG 9.11.3-1ubuntu1.3-Ubuntu <<>> 192.168.1.1
;; global options: +cmd
;; connection timed out; no servers could be reached
$ nslookup 192.168.1.1
;; connection timed out; no servers could be reached
这些命令还提供指示问题的输出。
Ping google.com
dig google.com
所有这些命令(或其替代方法)都可以在Windows命令提示符下正常工作。
我在这里找到了解决方法:
它说我应该在/etc/resolv.conf中添加followinginng行。如果我这样尝试,它会起作用。
nameserver 192.168.1.1
nameserver 8.8.8.8
nameserver fcc0:0:0:ffff::1
nameserver fcc0:0:0:ffff::2
此后,ping google.com
和dig google.com
可以正常工作。但是我可以看到它用来解析的名称服务器是8.8.8.8
。
如果我连接到VPN,它将自己的名称服务器添加到/etc/resolv.conf中,然后,解析URL就没有问题了。 VPN断开连接后,问题再次出现。
注意:
以前没有这样的问题。 上一天,我们更改了路由器以使用新的ISP的连接,然后发生了问题。 同一网络中的其他计算机没有此问题。
为什么会发生这种情况以及如何正确解决此WSL问题?
为什么我们网络中只有一台计算机可以ping通,但无法挖掘到默认网关?
更新:
我看到路由表中有两个条目被标记为默认条目:
$ ip route show table all | grep default
none default via 192.168.0.1 dev wifi0 proto unspec metric 0
none default via 192.168.1.1 dev eth6 proto unspec metric 0