Using Fiddler to implement wildcard DNS lookups

Posted on 12/09/2013

Wow, this is now the third post I've done on Fiddler rules. And sequentially at that (HttpOnly cookies and CORS were the previous 2 posts). What's up with that?  Seriously?  Yep.  Stuff happens.  And sometimes you have to use Fiddler to help out with that stuff.  In this case, I'm trying to set up multiple development environments to build apps for SharePoint 2013.  Anyways, this one is short and sweet compared to the other rules I've posted about, but it does have a wider application than just debugging web applications. 

What problem does this solve?

  1. You're building web applications with a hosting system that creates dynamic sub domains for your app (like the SharePoint app model)
  2. In production, you will use DNS techniques such as wildcard CNAME records against a purchased domain, but during development this doesn't work as easily.
    1. You're working with a team of developers, and you may not always be able to share the same development domain name
    2. Your network admin doesn't want to maintain forward lookup zones for development in the production DNS
      1. Even if you had a development DNS, you'd have to manage it and then jack with your TCP/IP settings and detach your normal DHCP configuration to add a new primary DNS server (and who needs all that noise?)
    3. Your hosts file does not support wildcard entries
  3. Or, perhaps you've always wanted wildcard entries in your hosts file for subdomains? 

How do I set this bad boy up?

UPDATE - 12/10/13: Please see the comment below from Eric regarding a more appropriate solution that avoids the rule definition.

First, you're going to create the rule definition.  Notice how the default is true for the rule instead of it normally being false/disabled?  I did this to simulate how your hosts file is "always on", but dude, change it if it's getting in your way. 

I named this one for what I'm using it for (SharePoint app domains), but you would create a separate rule for each domain that you want redirected.  Can you store all of these rules in a database and look them up at run-time instead of creating all these rules?  Yes, you can find an example of using a database if you want to do that, but JScript.NET is "not the modern programming environment you're looking for" to help you out, so caveat emptor.

public static RulesOption("SharePoint App Domain Override")
var m_SharePointAppDomain: boolean = true;

Then, add the following code to the OnBeforeRequest handler.

// replaces need of wildcard CNAME in DNS
if (m_SharePointAppDomain) {
    if (oSession.hostname.EndsWith("")) {
        oSession.bypassGateway = true;                       
        oSession["x-overrideHost"] = "mydevserver";  // DNS name or IP address of target server

Hope this helps that fraction of you out there needing a good solution to this.  Perhaps my next post will be "Using Fiddler to make bacon pancakes"!

1 comment:

  1. Thanks for the post! FWIW, Fiddler's Tools > HOSTS feature also supports wildcards. So you can have rules like: