如何为我的`/etc/resolv.conf`设置`chattr +i`?

scr*_*apy 6 debian xattr

我的操作系统:debian9。
我磁盘上的文件系统:

$ sudo blkid  | awk '{print $1 ,$3}'
/dev/sda2: TYPE="ext4"
/dev/sda1: TYPE="vfat"
/dev/sda3: TYPE="ext4"
/dev/sda4: TYPE="ext4"
/dev/sda5: TYPE="swap"
Run Code Online (Sandbox Code Playgroud)

现在chattr +i为我的/etc/resolv.conf

sudo chattr +i /etc/resolv.conf
chattr: Operation not supported while reading flags on /etc/resolv.conf
ls -al /etc/resolv.conf
lrwxrwxrwx 1 root root 31 Jan  8 15:08 /etc/resolv.conf -> /etc/resolvconf/run/resolv.conf
sudo  mount -o remount,acl /
sudo chattr +i  /etc/resolvconf/run/resolv.conf
chattr: Inappropriate ioctl for device while reading flags on /etc/resolvconf/run/resolv.conf
Run Code Online (Sandbox Code Playgroud)

如何设置 chattr +i为我的/etc/resolve.conf

  1. /dev/sda1 对于 windows 是空的。

  2. 我的 debian 安装在 /dev/sda2

    $ df 
    Filesystem     1K-blocks     Used Available Use% Mounted on
    udev             1948840        0   1948840   0% /dev
    tmpfs             392020     5848    386172   2% /run
    /dev/sda2       95596964 49052804  41644988  55% /
    
    Run Code Online (Sandbox Code Playgroud)
  3. acl 已安装。

    $ dpkg -l acl    
    Desired=Unknown/Install/Remove/Purge/Hold   
    | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
    |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)    
    ||/ Name           Version      Architecture Description   
    +++-==============-============-============-=================================
    ii  acl            2.2.52-3+b1  amd64        Access control list utilities   
    
    Run Code Online (Sandbox Code Playgroud)
  4. 这些 findmnt 命令没有输出信息:

    sudo findmnt -fn / | grep -E "acl|user_xattr"
    sudo findmnt -fn / | grep vfat
    sudo findmnt -fn $(dirname $(realpath /etc/resolv.conf)) | grep tmpfs
    
    Run Code Online (Sandbox Code Playgroud)

小智 8

/etc/resolv.conf可能是一个符号链接。有关更多信息,请参阅此说明

你可以试试:

chattr +i "$(realpath /etc/resolv.conf)"
Run Code Online (Sandbox Code Playgroud)

根挂载点是否支持访问控制列表 (acl)扩展属性

通过以下方式检查:

findmnt -fn / | grep -E "acl|user_xattr" || echo "acl or user_xattr mount option not set for mountpoint /"
Run Code Online (Sandbox Code Playgroud)

您的根分区是“VFAT”类型吗?我相信“VFAT”不支持ACL

通过以下方式检查:

findmnt -fn / | grep vfat
Run Code Online (Sandbox Code Playgroud)

或者也许您的符号链接目标目录是tmpfstmpfs上的ACL丢失

测试一下:

findmnt -fn $(dirname $(realpath /etc/resolv.conf)) | grep tmpfs && echo $(dirname $(realpath /etc/resolv.conf)) is tmpfs
Run Code Online (Sandbox Code Playgroud)

干杯

  • 它不是一个 xattr。 (2认同)

ilk*_*chu 6

如您所见,您似乎无法chattr在符号链接上设置属性。此外,它们在tmpfs. 该手册页chattr提到,

并非所有文件系统都支持或使用所有标志;请参阅特定于文件系统的手册页,例如btrfs(5)ext4(5)、 以及xfs(5)更多特定于文件系统的详细信息。

并且没有提到不可变标志或chattrtmpfs(5).

ACL或扩展属性什么都没有做这个,chattr属性都是直接存储在索引节点,因为看到了ext4这个表中的索引节点结构


您需要找到一些其他方法来防止您的程序修改它。如果你用静态文件替换符号链接,systemd-resolved应该足够聪明,可以不理会文件:

支持三种处理模式/etc/resolv.conf(请参阅 参考资料resolv.conf(5)):

· 或者,/etc/resolv.conf可能由其他包管理,在这种情况下systemd-resolved将读取它的 DNS 配置数据。在这种操作模式下systemd-resolved是这个配置文件的消费者而不是提供者。

请注意,此文件的选定操作模式是完全自动检测的,具体取决于/etc/resolv.conf是指向DNS 服务器/run/systemd/resolve/resolv.conf还是127.0.0.53作为 DNS 服务器列出 。

如果您有其他程序可能会修改它(如 DHCP 客户端),您将不得不查看有关重新配置它们的信息。或者chattr +i /etc/resolv.conf在将其设为静态文件而不是符号链接之后,但请注意,无论尝试编写它,可能都不喜欢由此产生的错误。


小智 5

sudo rm /etc/resolv.conf //remove the symlink
sudo nano /etc/resolv.conf //create the new file and populate it as you wish
sudo chattr +i /etc/resolv.conf //change its attributes as you wish.....
Run Code Online (Sandbox Code Playgroud)


小智 5

尝试使用 -f 标志

sudo chattr  -f   +i   /etc/resolv.conf
Run Code Online (Sandbox Code Playgroud)