LoginSignup
24
8

More than 5 years have passed since last update.

macでnslookupできるけどpingできない時の対処法

Posted at

mac で nslookup できるけど ping できないことがあり、解決方法を調べたのでメモします。

結論

僕のケースでは、次のコマンドで直りました。

sudo killall -HUP mDNSResponder

症状

なにかコード書いて、いざ git push しようとするとエラーになることがしばしばありました。
再起動すればとりあえず直るんですが1時間に1回とか再起動するハメになり面倒です。

$ git push
ssh: Could not resolve hostname github.com: nodename nor servname provided, or not known
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

DNS の不具合かなーと思ったんですが DNS とは疎通できています。

$ nslookup github.com
Server:        8.8.8.8
Address:    8.8.8.8#53

Non-authoritative answer:
Name:    github.com
Address: 192.30.255.113
Name:    github.com
Address: 192.30.255.112

ただし git push の他に ping とか curl も動きません。

$ ping github.com
ping: cannot resolve github.com: Unknown host

調査内容

なぜ名前解決できるのに ping が疎通しないかを調べたところ、 nslookup や dig は DNS サーバに問い合わせるのに対し、 ping や curl は mDNSResponder に問い合わせるのが理由のようでした(Ask Different: DNS Resolution Fails for ping and curl, but not dig)。

解決方法としては mDNSResponder を再起動すればよいようです(Ask Different: DNS not resolving on Mac OS X)。このQ&Aには再起動方法として次のコマンドが提案されています。

sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist

しかしこのコマンドを打つと Operation not permitted while System Integrity Protection is engaged というエラーメッセージとともに失敗します。

Qiita: El CapitanのSystem Integrity Protection(rootless)の解除方法 にはエラーを回避する方法が書かれていますが、同記事によると

System Integrity Protectionは、そもそもマルウェアからの攻撃をかわすためのセキュリティ機能のようなので不用意に設定をオフにするのは推奨されません。くれぐれも自己責任での実行をお願いします。

ということなのであまり気が進みません。

もう少し簡素な方法がないか調べたところ https://gist.github.com/mipmip/1844353 に mDNSResponder のプロセスにシグナルを送って再起動を行う方法があり、試してみたら症状から回復しました。

sudo killall -HUP mDNSResponder

本質的な原因は謎ですが、とりあえずこの対処療法で我慢中です。

関連記事

24
8
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
24
8