/etc/resolv.conf

本文解决了Ubuntu启动后网络配置文件被重置的问题,通过设置固定的DNS服务器并锁定配置文件防止被改动,确保了系统的网络连接稳定。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

每次启动ubuntu后 /etc/resolv.conf都被改动,把nameserver行都删掉了,导致上不了网,如何解决?

最笨的办法是每次启动后在/etc/resolv.conf中加入两行

nameserver 127.0.0.1

nameserver 192.168.1.1

其中 127.0.0.1是本地DNS,192.168.1.1是默认路由器
正确的应该是下面这样:

google@google:~$ cat /etc/resolv.conf

# Generated by NetworkManager

nameserver 127.0.0.1             //本地DNS地址

nameserver 202.96.134.33     //第一DNS地址

nameserver 202.96.128.86     //第二DNS地址

 

$ sudo chattr +i  /etc/resolv.conf      //阻止resolv.conf被修改

$ sudo chattr  -i /etc/resolv.conf       //解除对resolv.conf文件的写阻止,及允许对resolv.conf进行修改

显示文件 Attributes的命令是 lsattr /etc/resolv.conf

 

 

google@google:~$ sudo chattr +i  /etc/resolv.conf  

google@google:~$ lsattr /etc/resolv.conf

----i------------e- /etc/resolv.conf

google@google:~$ sudo chattr  -i /etc/resolv.conf  

google@google:~$ lsattr /etc/resolv.conf

-----------------e- /etc/resolv.conf

 

A file with the `i' attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. Only the superuser or a process pessessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值