PDA

View Full Version : [SOLVED] Can't edit /etc/resolv.conf file as root



azmiuzun
June 14th, 2010, 03:30 PM
i can't edit /etc/resolv.conf with root account (Ubuntu Server 8.02)

root@webserver:~# sudo vim /etc/resolv.conf

"/etc/resolv.conf"
"/etc/resolv.conf" E212: Can't open file for writing

root@webserver:~# ls -l /etc/resolv.conf
-rw-r--r-- 1 root root 287 2010-06-14 15:20 /etc/resolv.conf

_Mark_
June 14th, 2010, 03:41 PM
Try without sudo as you are logged on as root is not needed, dunno if this is the problem but worth a try

azmiuzun
June 14th, 2010, 03:50 PM
nothing changed..

root@webserver:~# vim /etc/resolv.conf
nameserver 194.0.0x.0x
nameserver 10.60.5x.3x
~
W10: Warning: Changing a readonly file

:wq!
"/etc/resolv.conf" E212: Can't open file for writing

surfer
June 14th, 2010, 03:53 PM
is your filesystem mounted readonly?

Bachstelze
June 14th, 2010, 03:53 PM
That's weird. Is it on a read-only file system, by any chance?

CharlesA
June 14th, 2010, 03:55 PM
Sounds like it's mounted readonly for some reason.

Check the output of this:


mount

azmiuzun
June 14th, 2010, 04:02 PM
root@webserver:~# mount
/dev/mapper/webserver-Root on / type ext3 (rw,relatime,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
/sys on /sys type sysfs (rw,noexec,nosuid,nodev)
varrun on /var/run type tmpfs (rw,noexec,nosuid,nodev,mode=0755)
varlock on /var/lock type tmpfs (rw,noexec,nosuid,nodev,mode=1777)
udev on /dev type tmpfs (rw,mode=0755)
devshm on /dev/shm type tmpfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw,relatime)
securityfs on /sys/kernel/security type securityfs (rw)

CharlesA
June 14th, 2010, 06:16 PM
That looks fine, I'd suggest running fsck on it from a livecd if you can. Just to make sure there are no problems.

doas777
June 14th, 2010, 06:22 PM
it's conceivable that the file is locked by another process (network-manager mabye?).

arrrghhh
June 14th, 2010, 06:32 PM
it's conceivable that the file is locked by another process (network-manager mabye?).

I'd hope that wouldn't be running on a server...


Can you do an lsof and grep for that file? See if it is indeed in use?

azmiuzun
June 15th, 2010, 07:54 AM
root@webserver:/# lsof /etc/resolv.conf
root@webserver:/# lsof /etc
root@webserver:/#

surfer
June 15th, 2010, 08:03 AM
just to be sure it's not the filesystem. can you edit /etc/hosts (or any other file below / )?

azmiuzun
June 15th, 2010, 08:13 AM
i can edit /etc/hosts and other system files.

root@webserver:/# vim -w /etc/resolv.conf
i can append /etc/resolv.conf and save, but i can't edit this file

surfer
June 15th, 2010, 09:27 AM
hmmm. and brute force: delete and recreate? it does not work anyway now with your current resolv.conf, right?

azmiuzun
June 15th, 2010, 10:10 AM
i solve the problem, thanks everybody..


root@webserver:~# lsattr /etc/resolv.conf
----ia------------ /etc/resolv.conf

root@webserver:~# chattr -a /etc/resolv.conf

root@webserver:~# lsattr /etc/resolv.conf
----i------------- /etc/resolv.conf

root@webserver:~# chattr -i /etc/resolv.conf

root@webserver:~# lsattr /etc/resolv.conf
------------------ /etc/resolv.conf

root@webserver:~# vim /etc/resolv.conf
root@webserver:~#


i found the solution from this blog
Make your files immutable which even root can't delete (http://linuxhelp.blogspot.com/2005/11/make-your-files-immutable-which-even.html)

xlyz
December 30th, 2012, 12:46 PM
i solve the problem, thanks everybody..

root@webserver:~# chattr -i /etc/resolv.conf

i found the solution from this blog
Make your files immutable which even root can't delete (http://linuxhelp.blogspot.com/2005/11/make-your-files-immutable-which-even.html)

thanks. you saved my day :)