看来我的 root 配置无法访问 DNS,即使我的低权限用户可以访问 DNS。
$ ping google.com
PING google.com (142.251.32.110) 56(84) bytes of data.
64 bytes from 142.251.32.110 (142.251.32.110): icmp_seq=1 ttl=64 time=1.35 ms
64 bytes from 142.251.32.110 (142.251.32.110): icmp_seq=2 ttl=64 time=2.71 ms
^C
--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 1.350/2.029/2.708/0.679 ms
$ sudo -E ping google.com
ping: google.com: Name or service not known
这对 造成严重破坏apt-get
。我该如何解决这个问题?
我正在运行 WSL Ubuntu。
编辑1
看起来root
正在尝试用于localhost
DNS。
socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, IPPROTO_IP) = 5
setsockopt(5, SOL_IP, IP_RECVERR, [1], 4) = 0
connect(5, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
对于没有特权的我来说,等效的行是这样的。我认为这个172.*
地址是 WSL 的东西。
socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, IPPROTO_IP) = 5
setsockopt(5, SOL_IP, IP_RECVERR, [1], 4) = 0
connect(5, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("172.21.160.1")}, 16) = 0
这就是/etc/resolv.conf
看起来的样子。
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.21.160.1
编辑2
root无法读取/etc/resolv.conf
newfstatat(AT_FDCWD, "/etc/resolv.conf", 0x7ffc8a2d25f0, 0) = -1 EACCES (Permission denied)