Vagrantのhost-only設定がうまくいかない

Vagrantのhost-only設定で少し悩んでた。

config.vm.network :hostonly, "192.168.33.10"

どうやらこの書き方は古いらしく、こう書くのが正しいらしい。

config.vm.network :private_network, ip: "192.168.33.10"

sshの設定をconfigファイルに書き出し

$ vagrant ssh-config --host vagrantTest >> ~/.ssh/config

書き出したファイルはこんな感じ。

Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /USER/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL

あれ、HostNameが192.168.33.10じゃない。 NATからポートフォワーディングで接続する設定になってるぽい。 なので、192.168.33.10でアクセスできるように設定を変える。

Host default
  HostName 192.168.33.10
  User vagrant
  Port 22
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /USER/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL

これで無事sshで接続できた。

参考