在/etc/hosts 中定义别名的替代方法? [英] Alternative to defining aliases in /etc/hosts?

查看:47
本文介绍了在/etc/hosts 中定义别名的替代方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不编辑/etc/hosts文件的情况下,每次访问domain1.com时告诉我的计算机重定向到127.0.0.1code> 或 domain1.com 通过网络浏览器以及当我通过 curl 请求相同页面的内容时?

Is it possible, without editing the /etc/hosts file, tell my computer redirect to 127.0.0.1 every time I visit domain1.com or domain1.com through the web browser as well as when I request the content of the same pages through curl?

推荐答案

在您的机器上运行 DNS 服务器/解析器,配置为将无法解析的每个查询转发到上游的 DNS 解析器并设置/etc/resolv.conf .conf 将所有查询定向到本地运行的解析器.

Run a DNS server/resolver on your machine, configure to forward every query that it can't resolve to the DNS resolvers upstream and set /etc/resolv.conf to direct all queries to the locally running resolver.

然后在本地解析器中为要向 localhost 插入黑洞的域添加条目.

Then in the local resolver add entries for the domains you want to blackhole toward localhost.

有几个选项可供选择.当前最流行的缓存解析器是 unbound,但您也可以使用 dnscache 为它.

There are several of options to chose from. The currently most popular caching resolver is unbound, but you can also use dnscache for it.

这篇关于在/etc/hosts 中定义别名的替代方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆