Vagrant reverse port forwarding?

后端 未结 5 1830
栀梦
栀梦 2020-12-07 07:06

I\'m working on a web services architecture. I\'ve got some software that I need to run on the native host machine, not in Vagrant. But I\'d like to run some client services

5条回答
  •  余生分开走
    2020-12-07 08:09

    In the book Vagrant: Up and Running (Pub. date: June 12, 2013), written by the creator of Vagrant, he mentioned that it is not possible for guest machine to access services running on the host machine.

    Instead of using Forwarded Ports, you could set up a private network using Host-Only Networks.

    • Pros of using Host-Only Networks over Forwarded Ports

      1. Guest machines may access the services running on host machine

        This feature would solve your problem.

      2. Guest machines may access the services running on other guest machine

        This feature is very useful to separate services onto multiple machines to more accurately mimic a production environment.

      3. Secure

        Outside machines have no ways to access the services running on the guest machines

      4. Less work

        No need to configure every single Forwarded Port


    • How to configure Host-Only Networks

      config.vm.network :"hostonly", "192.168.0.0" # Vagrant Version #1

      config.vm.network :private_network, ip: "192.168.0.0" # Vagrant Version #2

      Having this line in your Vagrantfile will instruct vagrant to create a private network that has a static IP address: 192.168.0.0

      The IP address of the host is always the same IP address but with the final octet as a 1. In the preceding example, the host machine would have the IP address 192.168.0.1.

提交回复
热议问题