我们自己搭建了一个weather.sophia.com,多个版本的软件使用这个server,现在server经过变动,在部署之前,需要测试,因此需要搭建测试环境:如何让测试机器访问的weather.sophia.com都定位到test_server的地址。当测试完毕后,再将其真正部署上去。
一台路由器,设置路由器的域名重定向,这可以使得连接路由器的所有client,访问的域名都重定向到test_server。
而实际情况,手里的路由器并不支持域名重定向,因此第二种方案,搭建一个测试用DNS服务器test_DNS,将test_DNS加入到路由器的DNS服务器列表,这个搭建的test_DNS中将weather.sophia.com的域名重定向到具体ip地址。
而搭建DNS,我们采用dnsmasq,另外注意搭建DNS的机器不能是连接Route下的机器,因为路由器上设置DNS时,要求DNS与lan ip不能是同一网段。
现在,我们有以下硬件
Route下连接linux_clients和windows_clients,test_DNS并不连接在Route下。
这里我们的test_server是搭建在路由器下的一台机器,ip为192.168.0.2
配置dnsmasq.conf文件
no-resolv #dnsmasq将不在解析/etc/resolv.conf文件
address=/weather.sophia.com/192.168.0.2
listen_address=0.0.0.0 #
bind_interfaces #
If you don’t want dnsmasq to read /etc/resolv.conf or any other
file, getting its servers from this file instead (see below), then
uncomment this.
no-resolv
Add domains which you want to force to an IP address here.
The example below send any host in double-click.net to a local
web-server.
address=/weather.sophia.com/168.121.0.2
If you want dnsmasq to listen for DHCP and DNS requests only on
specified interfaces (and the loopback) give the name of the
interface (eg eth0) here.
Repeat the line for more than one interface.
#interface=
Or you can specify which interface not to listen on
#except-interface=
Or which to listen on by address (remember to include 127.0.0.1 if
you use this.)
listen-address=0.0.0.0
On systems which support it, dnsmasq binds the wildcard address,
even when it is listening on only some interfaces. It then discards
requests that it shouldn’t reply to. This has the advantage of
working even when interfaces come and go and change address. If you
want dnsmasq to really bind only the interfaces it is listening on,
uncomment this option. About the only time you may need this is when
running another nameserver on the same machine.
bind-interfaces
启动dnsmasq服务两种方式
sudo service dnsmasq reload/restart/start/stop
/etc/init.d/dnsmasq start
路由器中设置DNS为10.3.16.46,可以再添加其他的DNS服务器。
只需要刷新dns缓存,并check域名是否正确被重定向
sudo /etc/init.d/dns-clean
nslookup weather.sophia.com
若没有被正确重定向,则可能是路由器更改的DNS配置未及时更新所致,可以指定dns ip来check是否正确
nslookup weather.sophia.com 10.3.16.46
重新获取ip,重启网络服务
/etc/init.d/dhclient
/etc/init.d/network restart
nslookup weather.sophia.com
也可用dig +trace weather.sophia.com
ipconfig /flushdns
nslookup weather.sophia.com
若没有被正确重定向,则可能是路由器更改的DNS配置未及时更新所致,可以指定dns ip来check是否正确
nslookup weather.sophia.com 10.3.16.46
ipconfig /renew //ipconfig /all 正确显示了路由器设置的DNS
ipconfig /flushdns
ping weather.sophia.com
浏览器访问weather.sophia.com,正确被重定向。