wildcard in hosts file

情到浓时终转凉″ 提交于 2019-12-21 03:03:12

问题


It's not possible to use a wildcard in the hosts file on windows or linux. Is there a way to do it with a browser plugin or something else?

I have a dev server on a vbox instance so it's practically LAN. I'm creating .dev domain for my virtual hosts so example.com becomes example.dev. For an application I'm creating random subdomains (abd34dn.example.dev) which should all point to the dev server's IP.

What are my options?


回答1:


Instead of editing hosts file (which does not work for your requirement), setup a DNS server and setup Wildcard DNS A record -- like

*.example.dev IN  A  1.2.3.4

You mentioned subdomains, but I am assuming you actually want host entries (A address entries) under example.dev. Now abcd.example.dev indicates "abcd" is a host entry, and not a subdomain. Only if you say xyz.abcd.example.dev, then "abcd" becomes a subdomain. The key point is to say - since you want only abcd.example.dev - then you need only DNS A records and it is suggested as above.




回答2:


AngryHosts can act as a simple DNS, and it's just a tiny software and very easy to use.




回答3:


I made this simple tool to take the place of hosts. Regular expressions are supported. https://github.com/stackia/DNSAgent Windows only. Probably working with Mono.

A sample configuration:

[
    {
        "Pattern": "^.*$",
        "NameServer": "8.8.8.8"
    },
    {
        "Pattern": "^(.*\\.googlevideo\\.com)|((.*\\.)?(youtube|ytimg)\\.com)$",
        "Address": "203.66.168.119"
    },
    {
        "Pattern": "^.*\\.cn$",
        "NameServer": "114.114.114.114"
    },
    {
        "Pattern": "baidu.com$",
        "Address": "127.0.0.1"
    }
]



回答4:


You can use echoipdns for this (https://github.com/zapty/echoipdns).

By running echoipdns dev all requests for .dev subdomains are redirected to 127.0.0.1, so any domain with xyz.dev etc will resolve to 127.0.0.1. You can use any other suffix also just replace dev with name you want.

Echoipdns is even more powerful, when you want to use your url from other machines in network you can still use it with zero configuration.

For e.g. If your machine ip address is 192.168.1.100 you could now use a domain name xyz.192-168-1-100.dev which will always resolve to 192.168.1.100. This magic is done by the echoipdns by looking at the ip address in the second part of the domain name and returning the same ip address on DNS query. You will have to run the echoipdns on the machine from which you want to access the remote system.

echoipdns also can be setup as a standalone DNS proxy, so by just point to this DNS, you can now use all the above benefits without running a special command every time, and you can even use it from mobile devices.

So essentially this simplifies the wildcard domain based DNS development for local as well as team environment.

echoipdns works on Mac, Linux and Windows.

NOTE: I am author for echoipdns.



来源:https://stackoverflow.com/questions/4194655/wildcard-in-hosts-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!