请保持在root用户执行下方的命令~

查看端口占用

root@eya46:~# lsof -i:53
COMMAND   PID            USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
systemd-r 525 systemd-resolve   13u  IPv4  17884      0t0  UDP localhost:domain 
systemd-r 525 systemd-resolve   14u  IPv4  17885      0t0  TCP localhost:domain (LISTEN)

关闭占用的程序

# 禁止开机启动
systemctl disable systemd-resolved
# 停止运行
systemctl stop systemd-resolved

检查端口和DNS

再次运行lsof -i:53会发现,没有程序占用53端口了

但是dns也会出问题

例如运行ping baidu.com

ping baidu.com
ping: baidu.com: Temporary failure in name resolution

更改DNS

临时更改DNS

/etc/resolv.conf只要重启就会被清空...

首先临时更改下/etc/resolv.conf,要不然完全解析不了

vim /etc/resolv.conf

然后随便设置个dns nameserver 8.8.8.8

永久更改DNS

创建一个Bash脚本

#!/bin/bash

DNS_SERVERS=("8.8.8.8" "8.8.4.4")
if [ -e "/etc/resolv.conf" ]; then
        cp /etc/resolv.conf /etc/resolv.conf.backup
        sed -i '/nameserver/d' /etc/resolv.conf

        for dns_server in "${DNS_SERVERS[@]}"; do
                echo "nameserver $dns_server" | sudo tee -a /etc/resolv.conf
        done
        echo "DNS servers updated successfully."
else
        echo "/etc/resolv.conf does not exist."
fi

在添加运行权限chmod +x autodns.sh

设置开机自启

创建文件vim /etc/systemd/system/autodns.service

[Unit]
Description=autodns
After=network.target

[Service]
ExecStart=/bin/autodns.sh
ExecReload=/bin/autodns.sh
Restart=no
User=root

[Install]
WantedBy=default.target
systemctl enable autodns.service
systemctl start autodns.service

然后大功告成,这下重启服务器也会自动添加dns了

应该还有其它方法,但没找到...