Vagrant中网络配置一、基本配置Vagrant offers multiple options for how you are able to connect your guest machines to the network, but there is a standard usage pattern as well as some points common to all network configurations that are important to know. 1.1 配置项All networks are configured within your Vagrantfile using the config.vm.network method call. For example, the Vagrantfile below defines some port forwarding:
Every network type has an identifier such as :forwarded_port in the above example. Following this is a set of configuration arguments that can differ for each network type. In the case of forwarded ports, two numeric arguments are expected: the port on the guest followed by the port on the host that the guest port can be accessed by. 二、端口转发2.1 基本的配置
2.2 端口冲突检测和校验
当检测到端口发生冲突,Vagrant会自动在2200到2250直接的端口自动矫正。 2.3 UDP或者TCP协议
三、private 网络配置Private networks allow you to access your guest machine by some address that is not publicly accessible from the global internet. In general, this means your machine gets an address in the private address space. 3.1 DHCP
3.2 Static IPYou can also specify a static IP address for the machine. This lets you access the Vagrant managed machine using a static, known IP. The Vagrantfile for a static IP looks like this:
It is up to the users to make sure that the static IP doesn't collide with any other machines on the same network. 3.2.1 Distable auto-configurationIf you want to manually configure the network interface yourself, you can disable Vagrant's auto-configure feature by specifying auto_config:
三、public 网络配置Public networks are less private than private networks, and the exact meaning actually varies from provider to provider, hence the ambiguous definition. The idea is that while private networks should never allow the general public access to your machine, public networks can. 3.1 DHCPThe easiest way to use a public network is to allow the IP to be assigned via DHCP. In this case, defining a public network is trivially easy:
3.2 Static IPDepending on your setup, you may wish to manually set the IP of your bridged interface. To do so, add a :ip clause to the network definition.
3.3 Defalut network interfaceIf more than one network interface is available on the host machine, Vagrant will ask you to choose which interface the virtual machine should bridge to. A default interface can be specified by adding a :bridge clause to the network definition.
The string identifying the desired interface must exactly match the name of an available interface. If it can't be found, Vagrant will ask you to pick from a list of available network interfaces. |
|