前言

根据Linux DNS加载规则,如果单纯修改/etc/resolv.conf,并将自定义DNS置顶(优先级最高),在下次系统重启时,DNS优先级会被重置,即自定义DNS会被调整到末尾,优先级降低。

解决方法

/etc/resolv.conf文件内开头就有注释:

Generated by NetworkManager
  1. 修改/etc/NetworkManager/NetworkManager.conf,在main部分添加:
    dns = none
  2. 重启服务
    systemctl restart NetworkManager.service
  3. 修改/etc/resolv.conf
    nameserver 自定义DNS
    ...
  4. 重启网卡
    service network restart
    # 如果失败,尝试以下命令
    # 1. service network-manager restart
    # 2. service networking restart (Kali Linux(Debian)专用)
    # 3. nmcli c reload (CentOS 8专用)