Debian9系统下如何为/etc/resolv.conf设置chattr +i属性?
chattr +i Attribute on /etc/resolv.conf in Debian 9 Let's walk through the straightforward steps to make /etc/resolv.conf immutable using the chattr +i command, tailored to your Debian 9 setup:
Step 1: Check /etc/resolv.conf's file type
First, confirm if /etc/resolv.conf is a regular file or a symbolic link (some network configurations use symlinks here):
ls -l /etc/resolv.conf
If it's a symlink, you'll need to apply the attribute to the target file instead of the symlink itself—chattr doesn't work on symlinks directly.
Step 2: Apply the immutable attribute
Modifying file attributes requires root access, so run this command with sudo:
sudo chattr +i /etc/resolv.conf
This locks the file, preventing any user (including root) from modifying, deleting, or renaming it until you explicitly remove the attribute.
Step 3: Verify the attribute is active
To confirm the immutable flag is set correctly, use:
lsattr /etc/resolv.conf
You should see an i in the output (e.g., ----i--------e--- /etc/resolv.conf), which indicates the file is immutable.
Key Notes to Remember
- If you ever need to edit
/etc/resolv.conf, you must first remove the immutable attribute:
Make your changes, then re-runsudo chattr -i /etc/resolv.confsudo chattr +i /etc/resolv.confto lock it again. - Your
findmntcommand returning no output is odd, but since Debian is installed on/dev/sda2(almost certainly an ext4 filesystem, which supports the extended attributes required forchattr) and you have ACL installed, this shouldn't interfere with setting the immutable attribute. Just ensure you always usesudofor thechattrcommands to avoid permission issues.
内容的提问来源于stack exchange,提问作者scrapy

