开发者

Python script to change resolv.conf [Permission issue]

Hey everybody, I am just newbie at Python. I wanted to write a script in Python to change DNS.

But I learn开发者_如何学JAVAed that resolv.conf is read-only file, after writing that code. Because I took that error: IOError: [Errno 13] Permission denied: '/etc/resolv.conf'

myFile= open("/etc/resolv.conf", "w")

Then, I made a little search and found os.chmode() and I wrote a new line to remove all privileges of resolv.conf which is:

os.chmod("/etc/resolv.conf", 0777)

But now I'm taking that error: IOError: [Errno 13] Permission denied: '/etc/resolv.conf'

I can't get over this question and I'm waiting for your advices.

Thank you.


/etc/resolv.conf is typically owned by root. Unless your script is run in such a way that it has root privileges, it won't be able to change the file.


Chmod you must run as root before your script. And when you get permissions, your script will run without errors


You should never allow for a file like resolv.conf to be writable by all. It looks like you were chmod'ing it, or trying to anyway, to 777. That's really bad. There is a lot someone could do by changing a resolver on a host and making that host point to systems that were setup for malicious reasons. For example, one could have their own LDAP server, and by changing resolv.conf point a system at their resolver, and at their LDAP server, thereby possibly gaining privileged levels of access.

Keep this file locked down at all times.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜