Using wildcards in names in Windows hosts file

192,712

Solution 1

There is not. The hosts file isn't very clever, you have to list every subdomain individually (including www and no-www)

Solution 2

An answer to a very similar StackOverflow question worked well for me.

http://mayakron.altervista.org/support/browse.php?path=Acrylic&name=UserManual

Wildcard Support on XP at hostsfile. Enjoy.

Basically, this program Acrylic works as a DNS proxy for your local machine. Just point your Local Area Connection to 127.0.0.1, then edit the AcrylicHosts.txt in a very similar manner to the regular hosts file -- only with wildcards!

Solution 3

Dnsmasq is what you need but it doesn't work quite well on Windows. So I wrote an alternative on Windows called DNSAgent.

You can use regular expression in rules. There is also some advanced features like customizing cache TTL, non-standard-port DNS server, compression pointer mutation, etc. Open sourced under MIT license.

Solution 4

first, i agree with phoshi that its not possible to do what you want in the hosts-file of windows (neither on unix).

secondly, you have to get control over the result of a request to dns. one option is to use your own dns-resolving on your router (dnsmasq, dnscache+tinydns, bind, whatever, see quack's comment) and tweak it or to use a dns-resolver on windows which you can control as you want.

see here for a list of dns-resolvers, check for the "wildcard" column, maybe powerdns or maradns or posadis is something that fits your needs.

Share:
192,712

Related videos on Youtube

Saif Bechan
Author by

Saif Bechan

I am a Full Stack Web Developer with industry experience building websites and web applications. I specialize in JavaScript and have professional experience in working with PHP, Symfony, NodeJS, React, Redux and Apollo GraphQL. To ensure high quality and standards I have extensive knowledge on CI/CD pipelines such as GitLab CI and testing frameworks such as JUnit, PHPUnit and Cypress.

Updated on September 17, 2022

Comments

  • Saif Bechan
    Saif Bechan almost 2 years

    Is there a way to create a wildcard domain in the Windows hosts file.

    I tried this

    xxx.xxx.xxx.xxx *.somedomain.com

    This does not work, is there maybe some other syntax I should use?

    I am working on Windows 7

    • quack quixote
      quack quixote about 14 years
      i just answered a question on doing this with DNSmasq on ServerFault (not on windows, obviously, but on a router running DD-WRT/OpenWRT it's doable)
    • bvaughn
      bvaughn about 8 years
      XP SP2 included a castration of the host file - securityfocus.com/archive/1/431032/30/0/threaded Assumed reason is people were using it to block ads while browsing. This is a guess as far as I know Microsoft has never revealed why they did this and why they are rolling it forward to everything since. If you are able to put in a proxy server between your PC and the internet, then you could put in a block for what you wanted.
  • Arjan
    Arjan almost 14 years
    Given the last sentence, I assume www.example.com is not blocked by the first line, but only when adding 127.0.0.1 example.com?
  • 0x8badf00d
    0x8badf00d almost 14 years
    moonfern, I do not agree with your list. 127.0.0.1 somesite.com WILL NOT block all outgoing DNS requests ending with somesite.com, all it will block is somesite.com, not www.somesite.com or subdomain.somesite.com or the like.
  • leeand00
    leeand00 about 12 years
    Acrylic works great, but can confuse you if you are trying to access a machine with a dynamic IP address. I have machines connected to my home network, and I use a dynamic dns to set the ip for the domain name. I use Acrylic on my laptop and I was gone for a few days, in the mean time my ip changed, but Acrylic remembered it as being the old ip, and I couldn't access the site. But running the "Purge Acrylic Cache Data" program took care of the problem.
  • Owen Blacker
    Owen Blacker about 12 years
    That is definitely not the case on Windows, moonfern.
  • fixer1234
    fixer1234 almost 8 years
    "Consider whether..." is pretty ambiguous. What, exactly, are you recommending as the solution?
  • DavidPostill
    DavidPostill almost 8 years
    Please read the question again carefully. Your answer does not answer the original question.
  • SquarePowder
    SquarePowder almost 8 years
    fixer1234 -- I don't know what is the problem the poster wishes to solve, while they ask as though explicit wildcarding will address it. "Consider whether..." suggests something that might work. It's easy to try, and requires few characters. I know it works in some cases. Since I don't have enough context to understand the problem, I can't recommend a solution. David Postill -- I believe my answer addresses and is pertinent to the original question. But perhaps your own answer will work better.
  • Spero
    Spero over 6 years
    Unfortunately acrylic does not support DNS aliases, which makes it useless to me.
  • Mikl
    Mikl about 4 years
    I checked Acrylic.exe on virustotal.com and it shows 3 detections: SecureAge APEX - Malicious, eGambit - Unsafe.AI_Score_63%, BitDefenderTheta - Gen:NN.ZelphiF.34106.OGW@aOJ8akl
  • abc
    abc about 4 years
    XP SP1 included an upgrade to a castration of the host file.
  • JeffUK
    JeffUK over 3 years
    @Mikl I'm not defending it, it may be dangerous in it's own right but it is also likely that Acrylic sometimes gets bundled with viruses to redirect users' traffic
  • Joe
    Joe about 3 years
    I know the repository is archived now but I still find this quite useful. Could you explain how does the rules.cfg file works?