大网数据广告活动
服务器运维问答

Avoid Replacing DHCP-discovered DNS Resolvers?

· 52CE 我爱测

I am on CentOS 7.4 attempting to configure dnsmasq for DNS caching and per-zone DNS servers for running Consul. Essentially, the dnsmasq configuration boils down to this: # filter everything with consul in the name and send to lo…

问题原文

原帖链接 · Naftuli Kay · CC BY-SA 3.0

I am on CentOS 7.4 attempting to configure dnsmasq for DNS caching and per-zone DNS servers for running Consul. Essentially, the dnsmasq configuration boils down to this:

# filter everything with consul in the name and send to local consul resolver
server=/consul/127.0.0.1#8600

The problem I'm having is getting the local resolver into /etc/resolv.conf without replacing any other resolvers in the file.

I used to be able to do this using dhclient configuration like so:

prepend domain-name-servers 127.0.0.1;

Since everything is NetworkManager now, I have discovered that the way to use dnsmasq is to add the following line to the [main] section of /etc/NetworkManager/NetworkManager.conf:

dns=dnsmasq

Before restarting NetworkManager, I see that my /etc/resolv.conf contains the network DNS server received by DCHP:

# Generated by NetworkManager
search nowhere
nameserver 10.0.2.3
options single-request-reopen

Upon restarting NetworkManager with the above configuration change, it supersedes my network DNS server with 127.0.0.1:

# Generated by NetworkManager
search nowhere
nameserver 127.0.0.1
options single-request-reopen

Since dnsmasq uses the /etc/resolv.conf to detect local resolvers, I'd like to leave the resolver(s) in /etc/resolv.conf so that dnsmasq can discover them.

Is there a way to achieve the previous functionality of having NetworkManager just prepend the local resolver instead?

已采纳解答

原帖链接 · Naftuli Kay · CC BY-SA 3.0

Apparently even though CentOS 7.4 does not ship with an upstream /etc/dhclient.conf, this is still a valid path. I simply created this file with the following contents:

prepend domain-name-servers 127.0.0.1;

And voila!

# Generated by NetworkManager
search nowhere
nameserver 127.0.0.1
nameserver 10.0.2.3
options single-request-reopen

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-09-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。