Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> 關於伺服器

CentOS wget 無法解析域名:/etc/resolv.conf 修復實戰

編輯:關於伺服器

故障現象

wget https://down.example.com/
--2012-09-15 09:13:14--
Resolving blog.example.com... failed: Temporary failure in name resolution.
wget: unable to resolve host address

根因確認

cat /etc/resolv.conf
# 輸出:
nameserver 205.185.112.68
nameserver 205.185.112.69
# 這組 DNS 可能已失效/被封鎖/不支援遞迴查詢

立即修復:替換為公開高可用 DNS

vi /etc/resolv.conf
# 覆蓋為:
nameserver 208.67.222.222   # OpenDNS
nameserver 208.67.220.220   # OpenDNS
# 或推薦組合:
nameserver 1.1.1.1          # Cloudflare
nameserver 8.8.8.8          # Google
nameserver 223.5.5.5        # 阿里雲
nameserver 114.114.114.114  # 114DNS

驗證生效

wget https://down.example.com/
# 應正常解析並下載

# 更詳細測試
dig example.com @1.1.1.1
nslookup example.com 8.8.8.8

永久生效方案 (防 NetworkManager/重啟覆蓋)

CentOS 7 / RHEL 7

# 方法一:修改介面配置
vi /etc/sysconfig/network-scripts/ifcfg-eth0
DNS1=1.1.1.1
DNS2=8.8.8.8
PEERDNS=no
systemctl restart network

# 方法二:NetworkManager
nmcli con mod "System eth0" ipv4.dns "1.1.1.1 8.8.8.8"
nmcli con mod "System eth0" ipv4.ignore-auto-dns yes
systemctl restart NetworkManager

CentOS 8 / RHEL 8 / Rocky / AlmaLinux

# systemd-resolved
vi /etc/systemd/resolved.conf
[Resolve]
DNS=1.1.1.1 8.8.8.8
FallbackDNS=223.5.5.5 114.114.114.114
systemctl restart systemd-resolved

# 或 NetworkManager (同上)

VPS 特殊情況

  • 部分 VPS 商預設鎖定 /etc/resolv.conf (chattr +i),需先 chattr -i /etc/resolv.conf
  • OpenVZ 容器可能無法修改,需提交工單要求宿主機修復 DNS
  • 雲廠商通常提供內網 DNS (如 10.x.x.x),優先使用內網 DNS 解析內部服務

批次修復腳本 (多台伺服器)

#!/bin/bash
cat > /etc/resolv.conf <
Copyright © Windows教程網 All Rights Reserved