virtualbox+vagrant學習-3-Vagrant Share-4-Vagrant Connect
Vagrant Connect
vagrant可以共享到vagrant環境的任何或每個埠,而不僅僅是SSH和HTTP。“vagrant connect”命令為連線人員提供一個靜態IP,他們可以使用該IP與共享的vagrant環境通訊。傳送到此IP的任何TCP流量都被髮送到共享的vagrant環境。
1.Usage
即呼叫vagrant share --full命令
這將自動為遠端連線共享盡可能多的埠。更多資訊請檢視 the Vagrant share security page頁面。
注意在呼叫vagrant share --full命令末尾的共享名字,並將其提供給希望連線到你的機器的人。他們只需要簡單地呼叫vagrant connect NAME命令即可(和上一篇ssh的連線方法一樣)。這將給他們一個靜態IP,他們可以使用它來訪問你的vagrant環境。
userdeMacBook-Pro:~ user$ vagrant share --full --http 80 Vagrant Share now defaults to using the `ngrok` driver. The `classic` driver has been deprecated. For more information about the `ngrok` driver, please refer to the documentation: https://www.vagrantup.com/docs/share/ ==> default: Detecting network information formachine... default: Local machine address: 127.0.0.1 default: default: Note: With the local address (127.0.0.1), Vagrant Share can only default: share any ports you have forwarded. Assign an IP or address to your default: machine to expose all TCP ports. Consult the documentationdefault: for your provider ('virtualbox') for more information. default: default: Local HTTP port: 80 default: Local HTTPS port: disabled default: Port: 2222 ==> default: Creating Vagrant Share session... share: Importing base box 'hashicorp/vagrant-share'... share: Matching MAC address for NAT networking... share: Setting the name of the VM: share-fe65ef45-f050-4cc9-98ba-bd19ec32d8e0 share: Fixed port collision for 22 => 2222. Now on port 2200. share: Vagrant has detected a configuration issue which exposes a share: vulnerability with the installed version of VirtualBox. The share: current guest is configured to use an E1000 NIC type for a share: network adapter which is vulnerable in this version of VirtualBox. share: Ensure the guest is trusted to use this configuration or update share: the NIC type using one of the methods below: share: share: https://www.vagrantup.com/docs/virtualbox/configuration.html#default-nic-type share: https://www.vagrantup.com/docs/virtualbox/networking.html#virtualbox-nic-type share: Clearing any previously set network interfaces... share: Preparing network interfaces based on configuration... share: Adapter 1: nat share: Forwarding ports... share: 31338 (guest) => 65535 (host) (adapter 1) share: 22 (guest) => 2200 (host) (adapter 1) share: Running 'pre-boot' VM customizations... share: Booting VM... share: Waiting for machine to boot. This may take a few minutes... share: SSH address: 127.0.0.1:2200 share: SSH username: tc share: SSH auth method: password share: share: Inserting generated public key within guest... share: Removing insecure key from the guest if it's present... share: Key inserted! Disconnecting and reconnecting using new SSH key... share: Machine booted and ready! ==> share: ==> share: Your Vagrant Share is running! Name: budget_hello:agenda_design ==> share: ==> share: You're sharing full access to your Vagrant machine. This means that ==> share: another user can have access to your Vagrant machine by running: ==> share: ==> share: vagrant connect budget_hello:agenda_design ==> share: ==> share: HTTP URL: http://5fd8f0d7.ngrok.io ==> share: ==> share: ==> share: Your Vagrant Share is running! Name: budget_hello:agenda_design ==> share: ==> share: You're sharing full access to your Vagrant machine. This means that ==> share: another user can have access to your Vagrant machine by running: ==> share: ==> share: vagrant connect budget_hello:agenda_design ==> share: ==> share: HTTP URL: http://5fd8f0d7.ngrok.io ==> share:
相應虛擬機器也已經開啟:
2.How does it work?
vagrant connect的執行是通過做vagrant最擅長的事情:管理虛擬機器來實現的。vagrant connect使用VirtualBox或VMware(更多的提供者支援即將到來)建立了一個只佔用20 MB記憶體的小型虛擬機器。
然後,傳送到這個小型虛擬機器的任何流量都被代理到共享的vagrant環境,就好像它被定向到這個環境一樣。
$vagrant connect budget_hello:agenda_design
3.Beware: Vagrant Insecure Key
如果你正在使用的vagrant環境或box是受到vagrant不安全金鑰對(大多數公共box都是)的保護,那麼連線到SSH的任何人都可以輕鬆地使用SSH。
雖然你希望與你信任的人共享,但在某些環境中,你可能與類或conference共享,並且不希望它們能夠SSH進入。
在這種情況下,我們建議從vagrant計算機中更改或刪除不安全的金鑰。
最後,我們要注意,我們正在努力使之在使用vagrant share時,除非顯式允許,否則vagrant私鑰將被主動拒絕。但是,這個特性還沒有完成。