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:

Vagrant.configure("2") do |config|
config.vm.network "forwarded_port", guest: 80,host: 8080
end

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 基本的配置


Vagrant::configure("2") do |config|
config.vm.network "forwarded_port",guest:80,host:8080 end

2.2 端口冲突检测和校验


Vagrant::configure("2") do |config|
config.vm.network "forwarded_port",guest:80,host:8080,auto_correct: true end

当检测到端口发生冲突,Vagrant会自动在2200到2250直接的端口自动矫正。

2.3 UDP或者TCP协议


Vagrant::configure("2") do |config|
config.vm.network "forwarded_port",guest:80,host:8080,auto_correct: true,protocol: "tcp" end

三、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

Vagrant.configure("2") do |config|
config.vm.network "private_network",type: "dhcp"
end
This will automatically assign an IP address from the reserved address space. The IP address can be determined by using vagrant ssh to SSH into the machine and using the appropriate command line tool to find the IP, such as ifconfig.

3.2 Static IP

You 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:

Vagrant.configure("2") do |config|
config.vm.network "private_network", ip: "192.168.50.4"
end

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-configuration

If you want to manually configure the network interface yourself, you can disable Vagrant's auto-configure feature by specifying auto_config:

Vagrant.configure("2") do |config|
config.vm.network "private_network", ip: "192.168.50.4", auto_config: false
end

三、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 DHCP

The 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:

Vagrant.configure("2") do |config|
config.vm.network "public_network"
end

3.2 Static IP

Depending 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.

Vagrant.configure("2") do |config|
config.vm.network "public_network", ip: "192.168.0.17"
end

3.3 Defalut network interface

If 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.


Vagrant.configure("2") do |config|
config.vm.network "public_network", bridge: 'en1:Wi-Fi (AirPort)'
end

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.

Vagrant网络配置的更多相关文章

  1. vagrant虚拟化之多网卡网络配置

    vagrant虚拟化之多网卡网络配置 一.network改为public 二.查看本地主机网络的ip地址范围(最佳解决方案) 三.vagrant优秀博文 vagrant虚拟化之多网卡网络配置,通过am ...

  2. AIROBOT系统 之 网络配置

    需求背景 在上一个章节我们讲究了私有云的部署,但是会有一个问题,我如果在外面,如何访问家里电脑上部署的私有云服务?其实这个问题在扩大化说 就是 如何可以在家庭网络以外 可以访问到 家庭网络:公网 访问 ...

  3. Vagrant安装配置

    转载自:https://my.oschina.net/u/3424381/blog/888205 Vagrant安装配置 实际上Vagrant只是一个让你可以方便设置你想要的虚拟机的便携式工具,它底层 ...

  4. vagrant 虚拟机配置最佳实践

    Mac VirtualBox Vagrant 管理虚拟机 这篇文章定位是在理解了 vagrant 相关概念之后,教你如何灵活玩转自己的虚拟机配置 本文为 @favoorr 常用的 Mac Virtua ...

  5. Linux 入门之网络配置

    查看网络状态 ifconfig 修改网络参数 实验环境centos6.5,其他系统自行百度 ls /etc/sysconfig/network-scripts 显示所有文件, vi /etc/sysc ...

  6. linux配置网卡IP地址命令详细介绍及一些常用网络配置命令

    linux配置网卡IP地址命令详细介绍及一些常用网络配置命令2010-- 个评论 收藏 我要投稿 Linux命令行下配置IP地址不像图形界面下那么方 便,完全需要我们手动配置,下面就给大家介绍几种配置 ...

  7. 说说SQL Server 网络配置

    打开Sql Server Configuration Manager,里面显示了SQL Server的网络配置,这些到底表示什么含义呢? 图一:MSSQLSERVER的协议 这些配置选项,其实就是为了 ...

  8. [System] CentOS虚拟机系统克隆后的网络配置

    VMware Workstation 虚拟机在进行克隆 CentOS 系统之后,在克隆机上配置网卡时,会出现一些细节问题,讨论一二. 一.情景描述 克隆机上默认由 NetworkManager 服务管 ...

  9. Centos网络配置

    网上搜索:centos网络配置的方法,主要包括dns.网关.IP地址,主要是配置resolv.conf\network\ifcfg-eth0这些网络配置文件. 稍后我会就centos7的网络配置进行实 ...

随机推荐

  1. 解决win service 2003 IIS发布Gis网站后,访问地图服务出错,无法正常打开而且 事件查看器出现错误提示。

    错误详情: 应用程序-特定 权限设置未将 COM 服务器应用程序(CLSID 为{379376DB-AEA6-40D1-9491-9345E61EF6BE})的 本地 激活 权限授予用户 NT AUT ...

  2. 1.PhotoShop缩小图片的三种方式

    先声明,本人不是高前端的,若有不当或者不合理的地方,还望前端爱好者多多指教.此处只是留作个人记录备忘. PS中有三种缩小 1.视图缩小,那方法很多缩放工具.Ctrl+"-",导航器 ...

  3. asp.net mvc生命周期学习

    ASP.NET MVC是一个扩展性非常强的框架,探究其生命周期对用Mock框架来模拟某些东西,达到单元测试效果,和开发扩展我们的程序是很好的. 生命周期1:创建routetable.把URL映射到ha ...

  4. Using GUID to generate the unique file name in C#

    GUID, the abbreviation of "Global Unique Identifier", is a unique reference number used as ...

  5. style currentStyle getComputedStyle的区别和用法

    先介绍下层叠样式表的三种形式: 1.内联样式,在html标签中style属性设置. <p style="color:#f90">内联样式</p> 2.嵌入样 ...

  6. c 连接数据库 mysql

    sudo apt-get install mysql-server mysql-client 再装开发包代码:sudo apt-get install libmysqlclient15-dev 安装完 ...

  7. H5的本地存储

    localStorage(本地存储),可以长期存储数据,没有时间限制,一天,一年,两年甚至更长,数据都可以使用.sessionStorage(会话存储),只有在浏览器被关闭之前使用,创建另一个页面时同 ...

  8. PHP计划任务之关闭浏览器后仍然继续执行的函数 ignore_user_abort

    备忘一下这个函数: 函数名称:ignore_user_abort 本函数配置或取得使用端连接中断后,PHP 程序是否仍继续执行.默认值为中断连接后就停止执行.在 PHP 配置文件中 (php3.ini ...

  9. document模板

    http://bce.baidu.com/doc/CDS/GettingStarted.html

  10. NET Core 静态文件及JS包管理器(npm, Bower)的使用

    NET Core 静态文件及JS包管理器(npm, Bower)的使用 文章目录 在 ASP.NET Core 中添加静态文件 使用npm管理JavaScript包 使用Bower管理JavaScri ...