每次启动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.