wsl2:resolv.conf 顽固地被重新生成

wsl2:resolv.conf 顽固地被重新生成

我的 /etc/wsl.conf:

[network]
generateResolvConf = false

但是我的 /etc/resolv.conf 继续重新生成。我指定:

nameserver 8.8.8.8

却发现它变成了:

# 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.29.128.1

注意:我尝试了下面建议的解决方案,但都无济于事:

为什么我的 resolv.conf 文件每次都会重新生成?

答案1

似乎chattr +i需要不可变文件属性()。运行以下命令:

sudo unlink /etc/resolv.conf
echo 'nameserver 8.8.8.8' | sudo tee /etc/resolv.conf
sudo chattr -f +i /etc/resolv.conf

# Replace `tee` with `tee -a` if you want to keep wsl.conf modifications
echo $'[network]\ngenerateResolvConf = false' | sudo tee /etc/wsl.conf'

相关内容