From 004fe0e7bb0c17c4f0e0bc801440a6456d7b979d Mon Sep 17 00:00:00 2001 From: Tristan Rivoallan Date: Fri, 25 Sep 2015 18:11:22 +0200 Subject: [PATCH 1/4] Make DHCP IP configurable This makes it possible to have DHCP attribute IPs to guests under various subnets --- plugins/providers/virtualbox/action/network.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/providers/virtualbox/action/network.rb b/plugins/providers/virtualbox/action/network.rb index cf5ca3b47..f29111dd9 100644 --- a/plugins/providers/virtualbox/action/network.rb +++ b/plugins/providers/virtualbox/action/network.rb @@ -249,14 +249,16 @@ module VagrantPlugins auto_config: true, mac: nil, nic_type: nil, - type: :static + type: :static, + dhcp_ip: "172.28.128.1" }.merge(options) # Make sure the type is a symbol options[:type] = options[:type].to_sym # Default IP is in the 20-bit private network block for DHCP based networks - options[:ip] = "172.28.128.1" if options[:type] == :dhcp && !options[:ip] + options[:ip] = options[:dhcp_ip] if options[:type] == :dhcp && !options[:ip] + ip = IPAddr.new(options[:ip]) if ip.ipv4? From 2c6ef938c728a1dd37a568c7c49389392a5dfd10 Mon Sep 17 00:00:00 2001 From: Tristan Rivoallan Date: Mon, 28 Sep 2015 15:48:09 +0200 Subject: [PATCH 2/4] Fix failing network test --- plugins/providers/virtualbox/action/network.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/providers/virtualbox/action/network.rb b/plugins/providers/virtualbox/action/network.rb index f29111dd9..ec6768842 100644 --- a/plugins/providers/virtualbox/action/network.rb +++ b/plugins/providers/virtualbox/action/network.rb @@ -257,7 +257,7 @@ module VagrantPlugins options[:type] = options[:type].to_sym # Default IP is in the 20-bit private network block for DHCP based networks - options[:ip] = options[:dhcp_ip] if options[:type] == :dhcp && !options[:ip] + options[:ip] = options[:dhcp_ip] if options[:type] == :dhcp ip = IPAddr.new(options[:ip]) From 48df85008ccbf16c419fb808b1a8054542b96e6f Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Wed, 18 Nov 2015 16:31:44 -0800 Subject: [PATCH 3/4] Rebase and cleanup conditional --- plugins/providers/virtualbox/action/network.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/providers/virtualbox/action/network.rb b/plugins/providers/virtualbox/action/network.rb index ec6768842..452cc10ad 100644 --- a/plugins/providers/virtualbox/action/network.rb +++ b/plugins/providers/virtualbox/action/network.rb @@ -250,15 +250,14 @@ module VagrantPlugins mac: nil, nic_type: nil, type: :static, - dhcp_ip: "172.28.128.1" + dhcp_ip: "172.28.128.1", }.merge(options) # Make sure the type is a symbol options[:type] = options[:type].to_sym # Default IP is in the 20-bit private network block for DHCP based networks - options[:ip] = options[:dhcp_ip] if options[:type] == :dhcp - + options[:ip] ||= options[:dhcp_ip] if options[:type] == :dhcp ip = IPAddr.new(options[:ip]) if ip.ipv4? From 28ddd6927b7804548f45233b86de65430863c500 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Wed, 18 Nov 2015 16:41:20 -0800 Subject: [PATCH 4/4] Update docs --- website/docs/source/v2/networking/private_network.html.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/website/docs/source/v2/networking/private_network.html.md b/website/docs/source/v2/networking/private_network.html.md index e11c7b3c7..f142c94ca 100644 --- a/website/docs/source/v2/networking/private_network.html.md +++ b/website/docs/source/v2/networking/private_network.html.md @@ -43,6 +43,14 @@ 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`. +You can also specify the DHCP IP: + +```ruby +Vagrant.configure("2") do |config| + config.vm.network "private_network", type: "dhcp", dhcp_ip: "192.168.0.100" +end +``` + ## Static IP You can also specify a static IP address for the machine. This lets you