Skip to content

Instantly share code, notes, and snippets.

@richardpeng
Last active December 17, 2015 08:58
Show Gist options
  • Save richardpeng/5583370 to your computer and use it in GitHub Desktop.
Save richardpeng/5583370 to your computer and use it in GitHub Desktop.
Redirect all traffic on a wildcard domain to an IP address using Dnsmasq on Mac
# install dnsmasq with Brew
brew install dnsmasq
# follow instructions on how to create a config file and startup entries
# copy example config to live config file
cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
# install startup script
sudo cp -fv /usr/local/opt/dnsmasq/*.plist /Library/LaunchDaemons
# edit the configuration
vim /usr/local/etc/dnsmasq.conf
# listen on localhost
listen-address=127.0.0.1
# redirect all traffic to *.example.com to 127.0.0.1
address=/example.com/127.0.0.1
# make your computer use dnsmasq for DNS in System Preferences -> Advanced
# add 127.0.0.1 as the first DNS server entry for your connection
# /etc/resolv.conf is autogenerated on Mac and will be overwritten if you edit it
# you'll need to restart dnsmasq each time you make changes to the configuration file
# start dnsmasq
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
# stop dnsmasq
sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment