我需要/etc/resolv.conf
在前面添加一个条目。我的接口是enp0s3。所以我创建/etc/dhcp/dhclient-enp0s3.conf
并添加了这一行:
prepend domain-name-servers 127.0.0.2
当我重新启动 CentOS VM 时,NetworkManager 会自动创建此文件:/var/lib/NetworkManager/dhclient-enp0s3.conf
当我发现 /etc/dhcp 中的 dhclient-enp0s3.conf 文件被正确读取时:
[root@localhost network-scripts]# cat /var/lib/NetworkManager/dhclient-enp0s3.conf
# Created by NetworkManager
# Merged from /etc/dhcp/dhclient-enp0s3.conf
prepend domain-name-servers 127.0.0.2
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
option ms-classless-static-routes code 249 = array of unsigned integer 8;
option wpad code 252 = string;
also request rfc3442-classless-static-routes;
also request ms-classless-static-routes;
also request static-routes;
also request wpad;
also request ntp-servers;
但是,当我 cat 时/etc/resolv.conf
,前置的名称服务器不会出现在任何地方。我还运行dig
只是为了测试我的内部主机名是否可以正确解析,但它们不能。
既然 NetworkManager 配置似乎已生成,那么我该从哪里开始呢?
答案1
dhclient.conf(和其他 dhcp 配置文件)中的配置语句必须以分号终止。
所以prepend domain-name-servers 127.0.0.2;
应该这样做。