问题现象:在Ubuntu系统中修改/etc/resolv.conf dns文件不生效且修改后立即还原了,修改后尝试使用命令chattr +i给文件加锁,但报错“ chattr: Operation not supported while reading flags on /etc/resolv.conf ”通过努力查找,最终解决了这个问题,可参考如下两个方法解决
问题原因:Ubuntu 12.04 之后版本系统,DNS 文件由 resolvconf 模块接管,导致直接修改 /etc/resolv.conf文件不生效,重启后会还原。
解决方法:
三个解决方法,可以分别测试。
1、(推荐)禁用systemd-resolved服务并启用resolvconf。
分两步:
检查是否安装了resolvconf服务:
返回如下则表示有安装:sudo dpkg -l | grep resolvconf
如果未安装,请安装它,若有安装则请跳过。[email protected]:~# sudo dpkg -l | grep resolvconf
ii resolvconf 1.84ubuntu1 all name server information handler
禁用systemd-resolved服务:sudo apt-get install resolvconf
启用resolvconf服务:sudo systemctl stop systemd-resolved
sudo systemctl disable systemd-resolved
启用后再编辑/etc/resolv.conf文件写入如下规则即可生效了。sudo systemctl enable resolvconf
sudo systemctl start resolvconf
2、执行如下命令并重启后在修改文件并加锁即可。nameserver 100.100.2.138
nameserver 100.100.2.136
3、若方法1处理后还有问题,请参考如下方法dpkg -l | grep resolv
apt-get remove resolvconf
reboot
vim /etc/resolv.conf
chattr +i /etc/resolv.conf
希望对大家有帮助。cp /etc/resolv.conf /etc/resolv.conf1
sudo mv /etc/resolv.conf /etc/resolv.conf_bak
sudo mv /etc/resolv.conf1 /etc/resolv.conf
sudo vim /etc/resolv.conf
chattr +i /etc/resolv.conf
文章评论 本文章有个评论