wildcard in hosts file

后端 未结 4 1821
花落未央
花落未央 2021-02-10 16:48

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 vbo

相关标签:
4条回答
  • 2021-02-10 17:13

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

    0 讨论(0)
  • 2021-02-10 17:14

    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.

    0 讨论(0)
  • 2021-02-10 17:30

    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"
        }
    ]
    
    0 讨论(0)
  • 2021-02-10 17:36

    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.

    0 讨论(0)
提交回复
热议问题