Skip to content

Instantly share code, notes, and snippets.

@rayblair06
Forked from ogrrd/dnsmasq OS X.md
Created February 10, 2025 11:37
Show Gist options
  • Save rayblair06/271d93054e47acf77859213396586d4f to your computer and use it in GitHub Desktop.
Save rayblair06/271d93054e47acf77859213396586d4f to your computer and use it in GitHub Desktop.

Revisions

  1. @ogrrd ogrrd revised this gist Oct 23, 2020. 1 changed file with 51 additions and 3 deletions.
    54 changes: 51 additions & 3 deletions dnsmasq OS X.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,53 @@
    ## Never touch your local /etc/hosts file in OS X again
    # Never touch your local /etc/hosts file in OS X again

    # NOTE this has been done properly by a guy here: https://www.stevenrombauts.be/2018/01/use-dnsmasq-instead-of-etc-hosts/
    > To setup your computer to work with *.test domains, e.g. project.test, awesome.test and so on, without having to add to your hosts file each time.
    ## also never use .dev as a TLD for local dev work.
    ## Requirements

    * [Homebrew](https://brew.sh/)
    * Mountain Lion -> High Sierra

    ## Install
    ```
    brew install dnsmasq
    ```

    ## Setup

    ### Create config directory
    ```
    mkdir -pv $(brew --prefix)/etc/
    ```

    ### Setup *.test

    ```
    echo 'address=/.test/127.0.0.1' >> $(brew --prefix)/etc/dnsmasq.conf
    ```
    ### Change port for High Sierra
    ```
    echo 'port=53' >> $(brew --prefix)/etc/dnsmasq.conf
    ```

    ## Autostart - now and after reboot
    ```
    sudo brew services start dnsmasq
    ```

    ## Add to resolvers

    ### Create resolver directory
    ```
    sudo mkdir -v /etc/resolver
    ```

    ### Add your nameserver to resolvers
    ```
    sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/test'
    ```

    ## Finished

    That's it! You can run scutil --dns to show all of your current resolvers, and you should see that all requests for a domain ending in .test will go to the DNS server at 127.0.0.1

    ## N.B. never use .dev as a TLD for local dev work. .test is fine though.
  2. @ogrrd ogrrd revised this gist Oct 23, 2020. 1 changed file with 1 addition and 60 deletions.
    61 changes: 1 addition & 60 deletions dnsmasq OS X.md
    Original file line number Diff line number Diff line change
    @@ -2,63 +2,4 @@

    # NOTE this has been done properly by a guy here: https://www.stevenrombauts.be/2018/01/use-dnsmasq-instead-of-etc-hosts/

    ## You should go and do that now, ignore all of this.

    > To setup your computer to work with *.dev domains, e.g. project.dev, awesome.dev and so on, without having to add to your hosts file each time.
    ## Requirements

    * [Homebrew](http://mxcl.github.io/homebrew/)
    * Mountain Lion

    ## Install
    ```
    brew install dnsmasq
    ```

    ## Setup

    ### Create config directory
    ```
    mkdir -pv $(brew --prefix)/etc/
    ```

    ### Setup *.dev

    ```
    echo 'address=/.dev/127.0.0.1' > $(brew --prefix)/etc/dnsmasq.conf
    ```

    You should probably add `strict-order` to `dnsmasq.conf` to keep nameserver order of `resolv.conf` ([see here](https://gist.github.com/drye/5387341)).

    ## Autostart

    ### Work after reboot
    ```
    sudo cp -v $(brew --prefix dnsmasq)/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons
    ```

    ### Get it going right now
    ```
    sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
    ```

    ## Add to resolvers

    ### Create resolver directory
    ```
    sudo mkdir -v /etc/resolver
    ```

    ### Add your nameserver to resolvers
    ```
    sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/dev'
    ```

    ## Add local DNS to search order in System Preferences

    System Preferences > Network > Wi-Fi (or whatever you use) > Advanced... > DNS > add 127.0.0.1 to top of the list.

    ## Finished

    That's it! You can run scutil --dns to show all of your current resolvers, and you should see that all requests for a domain ending in .dev will go to the DNS server at 127.0.0.1
    ## also never use .dev as a TLD for local dev work.
  3. @ogrrd ogrrd revised this gist Dec 3, 2018. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion dnsmasq OS X.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,8 @@
    # Never touch your local /etc/hosts file in OS X again
    ## Never touch your local /etc/hosts file in OS X again

    # NOTE this has been done properly by a guy here: https://www.stevenrombauts.be/2018/01/use-dnsmasq-instead-of-etc-hosts/

    ## You should go and do that now, ignore all of this.

    > To setup your computer to work with *.dev domains, e.g. project.dev, awesome.dev and so on, without having to add to your hosts file each time.
  4. @ogrrd ogrrd revised this gist Aug 5, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion dnsmasq OS X.md
    Original file line number Diff line number Diff line change
    @@ -53,7 +53,7 @@ sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/dev'

    ## Add local DNS to search order in System Preferences

    System Preferences > Network > Wi-Fi (or whatever you use) > Advanced... > DNS > add 127.0.0.1 to top of the list
    System Preferences > Network > Wi-Fi (or whatever you use) > Advanced... > DNS > add 127.0.0.1 to top of the list.

    ## Finished

  5. @ogrrd ogrrd revised this gist Aug 5, 2013. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions dnsmasq OS X.md
    Original file line number Diff line number Diff line change
    @@ -51,6 +51,10 @@ sudo mkdir -v /etc/resolver
    sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/dev'
    ```

    ## Add local DNS to search order in System Preferences

    System Preferences > Network > Wi-Fi (or whatever you use) > Advanced... > DNS > add 127.0.0.1 to top of the list

    ## Finished

    That's it! You can run scutil --dns to show all of your current resolvers, and you should see that all requests for a domain ending in .dev will go to the DNS server at 127.0.0.1
  6. @ogrrd ogrrd revised this gist Jul 23, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion dnsmasq OS X.md
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@ mkdir -pv $(brew --prefix)/etc/
    echo 'address=/.dev/127.0.0.1' > $(brew --prefix)/etc/dnsmasq.conf
    ```

    You should probably add `strict-order` to `dnsmasq.conf` to keep nameserver order of `resolv.conf`
    You should probably add `strict-order` to `dnsmasq.conf` to keep nameserver order of `resolv.conf` ([see here](https://gist.github.com/drye/5387341)).

    ## Autostart

  7. @ogrrd ogrrd revised this gist Jul 23, 2013. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions dnsmasq OS X.md
    Original file line number Diff line number Diff line change
    @@ -25,6 +25,8 @@ mkdir -pv $(brew --prefix)/etc/
    echo 'address=/.dev/127.0.0.1' > $(brew --prefix)/etc/dnsmasq.conf
    ```

    You should probably add `strict-order` to `dnsmasq.conf` to keep nameserver order of `resolv.conf`

    ## Autostart

    ### Work after reboot
  8. @ogrrd ogrrd renamed this gist Jun 26, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  9. @ogrrd ogrrd renamed this gist Jun 21, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  10. @ogrrd ogrrd renamed this gist Jun 21, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  11. @ogrrd ogrrd revised this gist Jun 21, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Setup.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Never touch your local /etc/hosts file in OS X again

    > To setup your computer to work with *.dev domains, e.g. project.dev, awesome.dev and so on, without having to add to your hosts file each time
    > To setup your computer to work with *.dev domains, e.g. project.dev, awesome.dev and so on, without having to add to your hosts file each time.
    ## Requirements

  12. @ogrrd ogrrd revised this gist Jun 21, 2013. 1 changed file with 54 additions and 1 deletion.
    55 changes: 54 additions & 1 deletion Setup.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,54 @@
    _
    # Never touch your local /etc/hosts file in OS X again

    > To setup your computer to work with *.dev domains, e.g. project.dev, awesome.dev and so on, without having to add to your hosts file each time
    ## Requirements

    * [Homebrew](http://mxcl.github.io/homebrew/)
    * Mountain Lion

    ## Install
    ```
    brew install dnsmasq
    ```

    ## Setup

    ### Create config directory
    ```
    mkdir -pv $(brew --prefix)/etc/
    ```

    ### Setup *.dev

    ```
    echo 'address=/.dev/127.0.0.1' > $(brew --prefix)/etc/dnsmasq.conf
    ```

    ## Autostart

    ### Work after reboot
    ```
    sudo cp -v $(brew --prefix dnsmasq)/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons
    ```

    ### Get it going right now
    ```
    sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
    ```

    ## Add to resolvers

    ### Create resolver directory
    ```
    sudo mkdir -v /etc/resolver
    ```

    ### Add your nameserver to resolvers
    ```
    sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/dev'
    ```

    ## Finished

    That's it! You can run scutil --dns to show all of your current resolvers, and you should see that all requests for a domain ending in .dev will go to the DNS server at 127.0.0.1
  13. @ogrrd ogrrd created this gist Jun 21, 2013.
    1 change: 1 addition & 0 deletions Setup.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    _