QEMU虚拟机DNS解析失效(已按Arch Wiki规范配置)
解决虚拟机内systemd-resolved DNS解析失败问题
排查与修复步骤
确认systemd-resolved服务运行状态:
systemctl status systemd-resolved若服务未启动,执行以下命令启动并设置开机自启:
systemctl start systemd-resolved systemctl enable systemd-resolved检查
/etc/resolv.conf配置:
该文件需为指向/run/systemd/resolve/stub-resolv.conf的软链接,若链接异常,重新创建:ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf手动配置公共DNS服务器:
编辑/etc/systemd/resolved.conf,取消DNS行注释并添加公共DNS地址:[Resolve] DNS=8.8.8.8 1.1.1.1重启服务使配置生效:
systemctl restart systemd-resolved验证DNS服务器连通性:
先ping指定的DNS服务器,确认网络可达:ping 8.8.8.8 -c 3若不通,排查虚拟机网络模式(如NAT配置是否正常)、系统防火墙是否拦截53端口(DNS默认使用UDP/TCP 53端口)。
检查防火墙规则:
确保允许DNS端口的出站流量,以iptables为例:iptables -A OUTPUT -p udp --dport 53 -j ACCEPT iptables -A OUTPUT -p tcp --dport 53 -j ACCEPT
验证解析恢复
执行以下命令确认域名解析正常:
resolvectl query google.com ping google.com -c 3
内容的提问来源于stack exchange,提问作者Benedict Schlütter
相关产品推荐
相关产品推荐

