2

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

But I learned 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.

4

3 回答 3

6

/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.

于 2011-02-18T11:17:28.253 回答
0

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

于 2011-02-18T11:17:47.173 回答
0

你永远不应该允许像 resolv.conf 这样的文件对所有人都是可写的。看起来你正在修改它,或者无论如何都尝试到 777。这真的很糟糕。通过更改主机上的解析器并使该主机指向出于恶意原因设置的系统,有人可以做很多事情。例如,可以拥有自己的 LDAP 服务器,并通过更改 resolv.conf 将系统指向其解析器和 LDAP 服务器,从而可能获得特权级别的访问权限。

始终锁定此文件。

于 2011-02-18T17:12:07.960 回答