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

Is it possible to override a single domain name using dnsmasq?

· 52CE 我爱测

I have a server application that I'm running two instances of, production and development, namely: prod.example.com (10.0.0.1) dev.example.com (10.0.0.2) A third-party has written a client application which has been hardcoded to …

问题原文

原帖链接 · Matt · CC BY-SA 3.0

I have a server application that I'm running two instances of, production and development, namely:

prod.example.com (10.0.0.1)
dev.example.com (10.0.0.2)

A third-party has written a client application which has been hardcoded to point to prod.example.com. But, I want those requests to go to the dev.example.com server and I don't have access to the third-party source code.

I do have access (temporarily) to the LAN that the client and server are running on so I can use dnsmasq to resolve prod.example.com to 10.0.0.2, at which point my work here is done and the client application will be (unknowingly) talking to the development server (or so I thought).

I've gotten as far as adding the following config to dnsmasq.conf..

address=/prod.example.com/10.0.0.2

..which does work, but it has the side-effect of preventing all other domains from resolving.

How can I have my cake and eat it?

社区高分解答

原帖链接 · Jon Musselwhite · CC BY-SA 3.0

Add this line to /etc/dnsmasq.conf:

addn-hosts=/etc/dnsmasq.hosts

Then insert your domain names into /etc/dnsmasq.hosts:

10.0.0.1  prod.example.com.
10.0.0.2  dev.example.com.

Don't forget the period at the end of the domain name. It marks it as a TLD, not a local hostname.

As always after configuration changes, restart dnsmasq:

sudo service dnsmasq restart

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

资料来源与适用范围

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

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

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