您需要 登录 才可以下载或查看,没有账号?立即注册
/etc/systemd/resolved.conf
/run/systemd/resolve/resolv.conf
#!/bin/bash # 你要设置的 DNS,可自行修改 DNS1="8.8.8.8" DNS2="1.1.1.1" echo "正在配置 DNS..." # 修改 resolved.conf sudo bash -c "cat > /etc/systemd/resolved.conf" <<EOF [Resolve] DNS=$DNS1 $DNS2 FallbackDNS=114.114.114.114 DNSStubListener=yes EOF # 重启服务 sudo systemctl restart systemd-resolved # 确保 resolv.conf 是正确的链接 if [ ! -L /etc/resolv.conf ]; then sudo mv /etc/resolv.conf /etc/resolv.conf.bak sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf fi echo "DNS 修改完成!当前 DNS:" systemd-resolve --status | grep "DNS Servers" -A2
#!/bin/bash echo "正在恢复默认 DNS..." sudo bash -c "cat > /etc/systemd/resolved.conf" <<EOF [Resolve] # 恢复默认,不指定 DNS,让系统自动获取 EOF sudo systemctl restart systemd-resolved echo "DNS 已恢复为系统默认!" systemd-resolve --status | grep "DNS Servers" -A2
systemd-resolve --status | grep "DNS Servers" -A2
cat /etc/resolv.conf
举报
本版积分规则 发表回复 回帖后跳转到最后一页