在 CentOS 中“替换域名解析”通常指修改系统使用的 DNS 服务器或修改某个域名的解析结果。下面按常见场景说明。
vi /etc/resolv.conf
内容示例:
nameserver 8.8.8.8
nameserver 114.114.114.114
⚠️ 注意:如果使用了 NetworkManager,重启网络可能被覆盖。
查看网卡名:
nmcli connection show
修改 DNS(假设网卡是 eth0):
nmcli connection modify eth0 ipv4.dns "8.8.8.8 114.114.114.114"
nmcli connection modify eth0 ipv4.ignore-auto-dns yes
nmcli connection down eth0
nmcli connection up eth0
验证:
cat /etc/resolv.conf
适合测试或强制解析
vi /etc/hosts
示例:
127.0.0.1 localhost
192.168.1.10 example.com
优先级:/etc/hosts > DNS
验证:
ping example.com
只能靠:
/etc/hostsyum install dnsmasq -y
配置:
vi /etc/dnsmasq.conf
address=/example.com/192.168.1.10
启动:
systemctl enable dnsmasq
systemctl start dnsmasq
并将本机 DNS 指向:
nameserver 127.0.0.1
nslookup example.com
# 或
dig example.com
如果你能说明:
我可以给你更精确的操作步骤。