问题
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
?
回答1:
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.
Then in the local resolver add entries for the domains you want to blackhole toward localhost.
There are several of options to chose from. The currently most popular caching resolver is unbound, but you can also use dnscache for it.
来源:https://stackoverflow.com/questions/40438487/alternative-to-defining-aliases-in-etc-hosts