LoginSignup
17
18

More than 5 years have passed since last update.

osx で dnsmasq を homebrew で入れてみる

Posted at

前提条件

  • homebrew

インストール

brew install dnsmasq

設定

設定ファイルの雛形を利用する

cp `brew --prefix dnsmasq`/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf

LaunchDaemons から起動する

sudo cp `brew --prefix dnsmasq`/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist

試してみる

同一のマシンからだと確認がしにくいので、別のマシンから試す方がいいです。

どうしても自分のマシンから試す場合には、dnsmasqが利用する resolv.conf を変更しておかないと、循環参照に陥ってしまいます。

dnsmasq.conf
resolv-file=/etc/resolv.conf.dnsmasq

osx では、/etc/resolv.conf を書き換えても意味はなく、「システム環境設定>ネットワーク」からDNSサーバを変更する必要があります。

DNS キャッシュをクリアする

動作確認する前に、DNS キャッシュをクリアしておくとよいでしょう

sudo dscacheutil -flushcache

確認する

ping を打つなり host コマンドを使うなりしましょう。

% host hogegege
host hogegege
hogegege has address 127.0.0.1

ただし注意しないといけないのは、検索ドメインが設定されていると、hogegege はドメインをつけて検索されるので、 /etc/hosts にドメイン付きで記述するか、検索ドメインの設定を外すかが必要です。

この動作は/etc/hostsでの解決と異なるので、ハマリがちです。

/etc/hosts 等を変更したら

dnsmasqの再起動が必要です。

sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist

また、クライアント側でキャッシュをクリアしておくとすぐ確認できます

17
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
18