Skip to content

Instantly share code, notes, and snippets.

@iveskins
Forked from tmslnz/dnsmasq.md
Created June 25, 2020 07:33
Show Gist options
  • Select an option

  • Save iveskins/e6f599d5440cccb863a15aba2b4f8a8c to your computer and use it in GitHub Desktop.

Select an option

Save iveskins/e6f599d5440cccb863a15aba2b4f8a8c to your computer and use it in GitHub Desktop.

Revisions

  1. @tmslnz tmslnz revised this gist Sep 21, 2016. 1 changed file with 23 additions and 5 deletions.
    28 changes: 23 additions & 5 deletions dnsmasq.md
    Original file line number Diff line number Diff line change
    @@ -23,13 +23,31 @@ networksetup -setdnsservers "Thunderbolt Bridge" 127.0.0.1
    `dnsmasq` configuration is simple.

    ```plain
    # Hosts files. Multiple entries OK. Hosts syntax is OK
    addn-hosts=/etc/hosts-adverts
    addn-hosts=/etc/hosts-adobe
    addn-hosts=/etc/hosts-whatever
    domain-needed # Only lookup full domains
    bogus-priv # No reverse IP lookups
    no-resolv # Don't use DNS servers listed in resolv.conf
    no-poll # Don't poll changes in resolv.conf
    no-hosts # Don't read /etc/hosts
    # Any other host route
    # Host files
    addn-hosts=/etc/hosts-a
    addn-hosts=/etc/hosts-b
    # Wildcard .dev domain
    address=/dev/127.0.0.1
    # DNS Servers
    server=84.200.69.80 # DNS.WATCH
    server=8.8.8.8 # Google
    server=8.26.56.26 # Comodo Secure DNS
    # Listen for DHCP requests
    listen-address=127.0.0.1
    # TODO: look into forwarding DHCP options from router for captive networks, etc.
    # dhcp-option=option:dns-server,0.0.0.0,10.10.10.1
    ```

    ## Notes
  2. @tmslnz tmslnz revised this gist Sep 21, 2016. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions dnsmasq.md
    Original file line number Diff line number Diff line change
    @@ -13,10 +13,10 @@ The only practical option is to create a new _Network Location_ via _Network Pre
    This can be done via GUI or via Terminal. **Mutliple DNS servers can be passed**, and will be used in-order.

    ```shell
    networksetup -setdnsservers "Wi-Fi" 127.0.0.1 8.8.8.8
    networksetup -setdnsservers "Bluetooth PAN" 127.0.0.1 8.8.8.8
    networksetup -setdnsservers "Thunderbolt Ethernet" 127.0.0.1 8.8.8.8
    networksetup -setdnsservers "Thunderbolt Bridge" 127.0.0.1 8.8.8.8
    networksetup -setdnsservers "Wi-Fi" 127.0.0.1
    networksetup -setdnsservers "Bluetooth PAN" 127.0.0.1
    networksetup -setdnsservers "Thunderbolt Ethernet" 127.0.0.1
    networksetup -setdnsservers "Thunderbolt Bridge" 127.0.0.1
    ```

    # Set up dnsmasq
  3. @tmslnz tmslnz revised this gist Sep 17, 2016. 1 changed file with 24 additions and 0 deletions.
    24 changes: 24 additions & 0 deletions dnsmasq.md
    Original file line number Diff line number Diff line change
    @@ -50,3 +50,27 @@ The contents of the file would simply be:
    ```plain
    nameserver 127.0.0.1
    ```

    # Changing and reloading the configurations

    ## Reloading resolver configuration

    Changes in the `/etc/resolver/*` are automatically read and applied.

    ## Reloading dnsmasq configuration

    `dnsmasq.conf` is read once at load. In order to refresh it the `dnsmasq` service needs to be restarted. `homebrew.mxcl.` below only applies if `dnsmasq`was installed via Homebrew ([https://brew.sh/]())

    ```shell
    sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
    sudo sudo launchctl stop homebrew.mxcl.dnsmasq
    sudo sudo launchctl start homebrew.mxcl.dnsmasq
    ```
    ## Reloading dnsmasq hosts

    If you have set `dnsmasq` to load _hosts_ from external files (`addn-hosts=…`), then those file changes can be updated by sending `SIGHUP` to `dnsmasq` like this:

    ```shell
    sudo pkill -SIGHUP dnsmasq
    ```

  4. @tmslnz tmslnz created this gist Sep 17, 2016.
    52 changes: 52 additions & 0 deletions dnsmasq.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    # Install dnsmasq
    Via brew or other method

    # Set up DNS resolver order
    In order to work on every connection and on any TLD, `dnsmasq` needs to be the _first_ DNS resolver receving the query.

    And since `dnsmasq` is a local process, all DNS queries need to go to `127.0.0.1`

    On **macOS**, `/etc/resolv.conf` is automaticaly created, depending on a variety of things (network settings, etc), so it **cannot be edited**.

    The only practical option is to create a new _Network Location_ via _Network Preferences_, and set all interfaces (Wi-Fi, Thunderbolt Ethernet, etc) to use a static DNS server address.

    This can be done via GUI or via Terminal. **Mutliple DNS servers can be passed**, and will be used in-order.

    ```shell
    networksetup -setdnsservers "Wi-Fi" 127.0.0.1 8.8.8.8
    networksetup -setdnsservers "Bluetooth PAN" 127.0.0.1 8.8.8.8
    networksetup -setdnsservers "Thunderbolt Ethernet" 127.0.0.1 8.8.8.8
    networksetup -setdnsservers "Thunderbolt Bridge" 127.0.0.1 8.8.8.8
    ```

    # Set up dnsmasq
    `dnsmasq` configuration is simple.

    ```plain
    # Hosts files. Multiple entries OK. Hosts syntax is OK
    addn-hosts=/etc/hosts-adverts
    addn-hosts=/etc/hosts-adobe
    addn-hosts=/etc/hosts-whatever
    # Any other host route
    address=/dev/127.0.0.1
    ```

    ## Notes
    `dhcp-hostsdir`, `dhcp-optsdir` and `hostsdir` are not supported on **macOS**. Attempting to set these wil prevent `dnsmasq` to start.

    # The .dev domain
    Another popular use of dnsmasq is to route all whaveter**.dev** requests to `127.0.0.1`, to use for local development environments.

    In order for this setup to work, we need:

    1. A new DNS reolver entry in `/etc/resolver/`
    2. A config line in `dnsmasq.conf`

    For **(1)** simply create `/etc/resolver/dev`. The filename `dev` is used by `resolver (5)` to determin the domain it applies to (`.dev` in our case).

    The contents of the file would simply be:

    ```plain
    nameserver 127.0.0.1
    ```