Vagrant Notes forward multiple ports on the same machine – 如何在Vagrant上 Port Forward Multiple Port?

開始常常用Vagrant 來嘗試建立自己的VPS
今日又出現了小小的問題需要上網
如何在Vagrant上 Port Forward Multiple Port呢?

解決方法十分簡單…
我們只需要在VagrantFile 上在不同的Port forward上加上以下的設定便可以了

# config.vm.network "forwarded_port", guest: [port], host: [port]
  config.vm.network "forwarded_port", guest: 80, host: 8080
  config.vm.network "forwarded_port", guest: 22, host: 22

E.G.

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.provision "shell", path: "provision.sh"

  config.vm.network "forwarded_port", guest: 80, host: 8080
  config.vm.network "forwarded_port", guest: 22, host: 22
end

Hope you find it useful

Leave a Reply