Ubuntu虚拟机不能ping提示Temporary failure in name resolution

Ubuntu虚拟机不能ping提示Temporary failure in name resolution

问题原因

系统每次重启之后/etc/resolv.conf文件被删除

解决办法

  1. 执行命令sudo systemctl restart systemd-resolved.service
  2. 发现网络已经好了

后续解决

为了减少麻烦,避免每次重启系统都要执行上述命令,我们将此命令加入开机启动脚本中

方法如下:

  1. 首先到/etc/init.d 目录(该目录为启动目录)下,创建example.sh

    cd /etc/init.d
    sudo vim example.sh
    
  2. example.sh中写入以下内容

    #! /bin/bash
    sudo systemctl restart systemd-resolved.service
    exit 0
    
  3. 接着将改shell脚本加入到启动计划中,执行命令sudo update-rc.d example.sh defaults 90,其中90表示优先级,数字越大表示优先级越低,执行的时间越晚。

  4. 如果想要移除这个脚本,执行命令sudo update-rc.d -f example.sh remove

posted @ 2022-09-28 21:27  Weber·Bon  阅读(1283)  评论(0编辑  收藏  举报