Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wildcard in hosts file

Tags:

dns

hosts

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?

like image 461
pablo Avatar asked Dec 29 '22 05:12

pablo


2 Answers

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.

like image 54
rsmoorthy Avatar answered Jan 06 '23 03:01

rsmoorthy


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"
    }
]
like image 40
Stackia Avatar answered Jan 06 '23 01:01

Stackia