ksaitoの日記

日々試したことの覚え書き

sshのport forwarding

移転しました。

自動的にリダイレクトします。

vagrantで必要なポートをマッピングすると設定が増えていってしまうので、一時利用する場合には、sshポートフォワードで済ませると楽です。

確認

sshでの接続先を確認します。 vagrant ssh-configで必要な情報を確認できます。

$ vagrant ssh-config vagrant1
Host vagrant1
  HostName 127.0.0.1
  User vagrant
  Port 2200
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile "~/.vagrant.d/insecure_private_key"
  IdentitiesOnly yes
  LogLevel FATAL
$

ポートフォワード

ローカルマシンの8080からvagrant1の3142ポートにアクセスする場合には、下記のコマンドを実行したあとブラウザでhttp://localhost:8080にアクセスします。

$ ssh -i ~/.vagrant.d/insecure_private_key -p 2222 vagrant@localhost -L 8080:localhost:3142

-fオプションと-Nオプションでバックグラウンドでポートフォワードしてくれます。