macにdnsmasqをインストール
macにdnsmasqをインストール
boxenにdnsmasqが入っていたので気になって入れてみました。
dnsmasqはローカルに起動できるdnsサーバです。
環境はMountain Lionです。
Homebrewでインストール
上記の通りConfファイルをコピー
上記の通りパスを通す。
コマンドが認識されているか確認
launchctlを利用して自動的に起動されるように設定ファイルを用意してくれています。
多分、間違いなく常時利用するので、使わせていただきましょう。
設定ファイルをコピー
設定ファイルを読みこませる(Daemonとして自動的に起動する)
プロセス確認
常時起動リストに入っているかの確認
ちなみに設定ファイルはこんな感じ
通常の起動の場合
再起動するとき(停止するとDaemonなので自動的に再起動される)
停止するとき(今後自動起動もしなくなる)
参考リンク
LaunchDaemons (launchctl, launchd.plist) の使い方 - maruko2 Note.
http://www.maruko2.com/mw/LaunchDaemons_(launchctl,_launchd.plist)_%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B9
boxenにdnsmasqが入っていたので気になって入れてみました。
dnsmasqはローカルに起動できるdnsサーバです。
環境はMountain Lionです。
Homebrewでインストール
$ brew install dnsmasq
==> Downloading http://www.thekelleys.org.uk/dnsmasq/dnsmasq-2.65.tar.gz
######################################################################## 100.0%
==> make install PREFIX=/usr/local/Cellar/dnsmasq/2.65
==> Caveats
To configure dnsmasq, copy the example configuration to /usr/local/etc/dnsmasq.conf
and edit to taste.
  cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
To have launchd start dnsmasq at startup:
    sudo cp -fv /usr/local/opt/dnsmasq/*.plist /Library/LaunchDaemons
Then to load dnsmasq now:
    sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
Warning: /usr/local/sbin is not in your PATH
You can amend this by altering your ~/.bashrc file
==> Summary
🍺  /usr/local/Cellar/dnsmasq/2.65: 7 files, 416K, built in 16 seconds
上記の通りConfファイルをコピー
$ ls -l /usr/local/opt/dnsmasq/dnsmasq.conf.example -rw-r--r-- 1 hoge wheel 25062 12 14 20:48 /usr/local/opt/dnsmasq/dnsmasq.conf.example $ cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
上記の通りパスを通す。
$ vi ~/.bashrc PATHに /usr/local/sbin を追加 $ source ~/.bashrc
コマンドが認識されているか確認
$ which dnsmasq /usr/local/sbin/dnsmasq問題ないですね。
launchctlを利用して自動的に起動されるように設定ファイルを用意してくれています。
多分、間違いなく常時利用するので、使わせていただきましょう。
設定ファイルをコピー
$ sudo cp -fv /usr/local/opt/dnsmasq/*.plist /Library/LaunchDaemons
設定ファイルを読みこませる(Daemonとして自動的に起動する)
$ sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
プロセス確認
$ ps aux | grep dnsmasq | grep -v grep nobody 2854 0.0 0.0 2432960 676 ?? Ss 4:48PM 0:00.00 /usr/local/opt/dnsmasq/sbin/dnsmasq --keep-in-foreground
常時起動リストに入っているかの確認
$ sudo launchctl list | egrep "dnsmasq|PID" PID Status Label 2854 - homebrew.mxcl.dnsmasq
ちなみに設定ファイルはこんな感じ
$ cat /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>homebrew.mxcl.dnsmasq</string>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/local/opt/dnsmasq/sbin/dnsmasq</string>
      <string>--keep-in-foreground</string>
    </array>
    <key>KeepAlive</key>
    <dict>
      <key>NetworkState</key>
      <true>
    </true></dict>
  </dict></plist>
通常の起動の場合
再起動するとき(停止するとDaemonなので自動的に再起動される)
$ sudo launchctl stop homebrew.mxcl.dnsmasq
停止するとき(今後自動起動もしなくなる)
$ sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
参考リンク
LaunchDaemons (launchctl, launchd.plist) の使い方 - maruko2 Note.
http://www.maruko2.com/mw/LaunchDaemons_(launchctl,_launchd.plist)_%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B9
コメント
おうちPCやプリンターの DHCP & DNS サーバとして使うと便利ですよねー。