LoginSignup
1
0

More than 3 years have passed since last update.

VagrantのHomestead + MacOSで、mDNS を使って名前解決をする

Posted at

Homesteadを使ってLaravelプロジェクトを開発するべく、Laravel Homestead 6.0 Laravel に従って手順を進めていくと

Homesteadでは自動的にホストを解決できるように、mDNSによりホスト名を公開しています。Homestead.yamlファイルで、hostname: homesteadとセットすれば、このホストはhomestead.localで使用できます。MacOS、iOS、LinuxディストリビューションではmDNSがデフォルトでサポートされています。Windowsでは、Bonjour Print Services for Windowsをインストールする必要があります。

とあるが、providerにVagrantを使っていると、homestead.local の名前解決ができない場合がある。

macos側
$ ping homestead.local
ping: cannot resolve homestead.local: Unknown host
Homestead側
$ sudo apt install avahi-utils
(略)
$ avahi-browse -a -t
+   eth2 IPv6  (Macのhost名)                                        _companion-link._tcp local

Vagrantのネットワークアダプターをbridgeに変更することで、名前解決ができるようになる。

Vagrantfile

()
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
()
    config.vm.network "public_network", bridge: 'en0: Wi-Fi (AirPort)'
()
end
()

Vagrantfileを修正後、仮想マシンを再起動する。

macos側
$ ping homestead.local
PING homestead.local (192.168.11.66): 56 data bytes
64 bytes from 192.168.11.66: icmp_seq=0 ttl=64 time=0.448 ms
64 bytes from 192.168.11.66: icmp_seq=1 ttl=64 time=
Homestead側
$ avahi-browse -a -t
(略)
+   eth2 IPv4 (Macのhost名)                                       _companion-link._tcp local
(その他、ローカルネットワーク内の機器)
(略)

(参考)

1
0
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
1
0