Skip to content

Instantly share code, notes, and snippets.

@simonw
Created June 30, 2023 12:37
Show Gist options
  • Save simonw/07632d0154f5761119dc02ea8243d3dd to your computer and use it in GitHub Desktop.
Save simonw/07632d0154f5761119dc02ea8243d3dd to your computer and use it in GitHub Desktop.

Wildcard DNS on Mac

June 30, 2023 at 5:12:48 AM

system:

You are ChatGPT, a large language model trained by OpenAI, based on the GPT-4 architecture. You are chatting with the user via the ChatGPT iOS app. This means most of the time your lines should be a sentence or two, unless the user's request requires reasoning or long-form outputs. Never use emojis, unless explicitly asked to. Knowledge cutoff: 2021-09 Current date: 2023-06-30


ChatGPT:

There are a few ways you could do this. Here are two common methods:

  1. Dnsmasq: This is a lightweight network infrastructure utility for providing DNS, DHCP, router advertisements, and network boot. You can install it with Homebrew by running brew install dnsmasq. Then, you'll need to configure it to redirect all .localdev.local queries to 127.0.0.1. This can usually be done by adding a line like address=/.localdev.local/127.0.0.1 to the dnsmasq configuration file.

  2. Local DNS Server: You can set up a local DNS server, like BIND, that has a wildcard record for .localdev.local to point to 127.0.0.1. This is more complex and probably overkill for your needs, but it's more flexible and might be useful if you're doing more complicated network simulations.

Please note that after making these changes, you'll likely need to flush your DNS cache for the changes to take effect. On a Mac, you can do this by running sudo killall -HUP mDNSResponder in Terminal.


ChatGPT:

Sure, here is a step-by-step guide on how to install and configure Dnsmasq for your requirement on a Mac:

  1. Install Homebrew if you haven't done that yet. Open Terminal and paste the following command:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. Install Dnsmasq using Homebrew by running the following command:

    brew install dnsmasq
  3. Configure Dnsmasq. First, copy the default configuration file to the right place:

    cp $(brew list dnsmasq | grep /dnsmasq.conf.example$) /usr/local/etc/dnsmasq.conf
  4. Edit the Dnsmasq configuration file. You can use a text editor like nano or vim. Here's how you'd do it with nano:

    nano /usr/local/etc/dnsmasq.conf

    Once inside the configuration file, add the following line:

    address=/.localdev.local/127.0.0.1
    

    Press ctrl+X to exit, and confirm with Y to save the changes.

  5. Start Dnsmasq. You can do this with the following command:

    sudo brew services start dnsmasq

    This will also set Dnsmasq to start on boot.

  6. Add Dnsmasq as a resolver for .localdev.local domain. macOS needs to know that it should use Dnsmasq for .localdev.local domains. Create a resolver file for it:

    sudo mkdir -v /etc/resolver
    sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/localdev.local'
  7. Test your setup. You can do this by using the dig command to query a .localdev.local domain and checking that the response comes from Dnsmasq. Here's how:

    dig test.localdev.local @127.0.0.1

    You should see an ANSWER SECTION in the output with test.localdev.local pointing to 127.0.0.1.

  8. Flush your DNS cache. You can do this by running:

    sudo killall -HUP mDNSResponder

That should be it! All .localdev.local queries on your machine should now resolve to 127.0.0.1.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment