mac 使用 brew 安装 dnsmasq
不用每次改 host 文件了
不要更改 /etc/hosts 文件
要设置您的计算机使用 *.test 域名,例如 project.test,awesome.test 等,而不必每次都修改 host 文件。
环境
- macOS Sierra
- Homebrew
安装
brew install dnsmasq |
设置
创建配置目录
mkdir -pv $(brew --prefix)/etc/ |
设置重定向 *.test
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).
设置自动启动
设置开机启动
sudo cp -v $(brew --prefix dnsmasq)/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons |
加载
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist |
添加到解析
创建解析目录
sudo mkdir -v /etc/resolver |
把域名添加到解析
sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/dev' |
设置系统 DNS
把 127.0.0.1 设为最高优先级。
完成
你可以使用 scutil --dns 命令查看你的全部解析。
以后可以直接再 nginx 使用 *.test 域名即可,默认指向 127.0.0.1。不需再修改 /etc/hosts 文件。