diff --git a/plugins/providers/virtualbox/action/network.rb b/plugins/providers/virtualbox/action/network.rb index cf5ca3b47..452cc10ad 100644 --- a/plugins/providers/virtualbox/action/network.rb +++ b/plugins/providers/virtualbox/action/network.rb @@ -249,14 +249,15 @@ 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 ip = IPAddr.new(options[:ip]) if ip.ipv4? 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