路由器 设置DNS 域名拦截 重定向

编程知识 更新时间:2023-05-01 03:32:50

我们自己搭建了一个weather.sophia,多个版本的软件使用这个server,现在server经过变动,在部署之前,需要测试,因此需要搭建测试环境:如何让测试机器访问的weather.sophia都定位到test_server的地址。当测试完毕后,再将其真正部署上去。
一台路由器,设置路由器的域名重定向,这可以使得连接路由器的所有client,访问的域名都重定向到test_server。
而实际情况,手里的路由器并不支持域名重定向,因此第二种方案,搭建一个测试用DNS服务器test_DNS,将test_DNS加入到路由器的DNS服务器列表,这个搭建的test_DNS中将weather.sophia的域名重定向到具体ip地址。
而搭建DNS,我们采用dnsmasq,另外注意搭建DNS的机器不能是连接Route下的机器,因为路由器上设置DNS时,要求DNS与lan ip不能是同一网段。
现在,我们有以下硬件
Route下连接linux_clients和windows_clients,test_DNS并不连接在Route下。

  • Route
  • test_DNS 10.3.16.46
  • test_server 192.168.0.2
  • linux_clients 192.168.0.5
  • windows_clients 192.168.0.7

test_server

这里我们的test_server是搭建在路由器下的一台机器,ip为192.168.0.2

test_DNS

  1. ubuntu机器上 安装dnsmasq
    sudo apt-get install dnsmasq
  2. 配置dnsmasq.conf文件
    no-resolv #dnsmasq将不在解析/etc/resolv.conf文件
    address=/weather.sophia/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 to a local
    web-server.
    address=/weather.sophia/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

  3. 启动dnsmasq服务两种方式
    sudo service dnsmasq reload/restart/start/stop
    /etc/init.d/dnsmasq start

  4. check dnsmasq是否正确
    nslookup weather.sophia 10.3.16.46
    看weather.sophia的Address是否为192.168.0.2
    若不是,则刷新dns缓存
    sudo /etc/init.d/dns-clean

Route

路由器中设置DNS为10.3.16.46,可以再添加其他的DNS服务器。

linux_clients

只需要刷新dns缓存,并check域名是否正确被重定向
sudo /etc/init.d/dns-clean
nslookup weather.sophia
若没有被正确重定向,则可能是路由器更改的DNS配置未及时更新所致,可以指定dns ip来check是否正确
nslookup weather.sophia 10.3.16.46
重新获取ip,重启网络服务
/etc/init.d/dhclient
/etc/init.d/network restart
nslookup weather.sophia
也可用dig +trace weather.sophia

windows_clients

ipconfig /flushdns
nslookup weather.sophia
若没有被正确重定向,则可能是路由器更改的DNS配置未及时更新所致,可以指定dns ip来check是否正确
nslookup weather.sophia 10.3.16.46
ipconfig /renew //ipconfig /all 正确显示了路由器设置的DNS
ipconfig /flushdns
ping weather.sophia
浏览器访问weather.sophia,正确被重定向。

更多推荐

路由器 设置DNS 域名拦截 重定向

本文发布于:2023-04-23 08:24:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/a3a103fab06a743ba5153395a46ec61c.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由器   重定向   域名   DNS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 98143文章数
  • 25000阅读数
  • 0评论数