You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Debian9系统下如何为/etc/resolv.conf设置chattr +i属性?

How to Set the 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:
    sudo chattr -i /etc/resolv.conf
    
    Make your changes, then re-run sudo chattr +i /etc/resolv.conf to lock it again.
  • Your findmnt command returning no output is odd, but since Debian is installed on /dev/sda2 (almost certainly an ext4 filesystem, which supports the extended attributes required for chattr) and you have ACL installed, this shouldn't interfere with setting the immutable attribute. Just ensure you always use sudo for the chattr commands to avoid permission issues.

内容的提问来源于stack exchange,提问作者scrapy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:02:16