hashicorp/vagrant · error · Vagrant::Errors::NetworkAddressInvalid

Network settings specified in your Vagrantfile define an inv

Error message

Network settings specified in your Vagrantfile define an invalid
IP address. Please review the error message below and update your
Vagrantfile network settings:

  Address: %{address}
  Netmask: %{mask}
  Error: %{error}

What it means

While classifying Vagrantfile network definitions, the Network action constructs IPAddr.new(options[:ip]) whenever a network block has an :ip but no explicit :type, to decide between :static and :static6. Any IPAddr::Error (invalid address, wrong family, bad mask) is rescued and re-raised as NetworkAddressInvalid with the address, netmask and the underlying parser message.

Source

Thrown at plugins/providers/virtualbox/action/network.rb:89

              slot = available_slots.shift
            end

            # Internal network is a special type
            if type == :private_network && options[:intnet]
              type = :internal_network
            end

            if !options.key?(:type) && options.key?(:ip)
              begin
                addr = IPAddr.new(options[:ip])
                options[:type] = if addr.ipv4?
                                   :static
                                 else
                                   :static6
                                 end
              rescue IPAddr::Error => err
                raise Vagrant::Errors::NetworkAddressInvalid,
                      address: options[:ip], mask: options[:netmask],
                      error: err.message
              end
            end

            # Configure it
            data = nil
            if type == :private_network
              # private_network = hostonly
              data = [:hostonly, options]
            elsif type == :public_network
              # public_network = bridged
              data = [:bridged, options]
            elsif type == :internal_network
              data = [:intnet, options]
            end

            # Store it!

View on GitHub (pinned to 35f3160f4a)

Solutions

  1. Fix the ip value in the Vagrantfile to a literal valid IPv4/IPv6 address (e.g. '192.168.33.10') or CIDR ('10.20.30.40/24')
  2. If you meant DHCP, remove the :ip key entirely and use type: 'dhcp'
  3. Quote values coming from variables/ERB so nil or empty strings never reach ip:
  4. Validate locally: `ruby -r ipaddr -e "puts IPAddr.new(ARGV[0])" '<value>'`

Example fix

# Vagrantfile - before:
config.vm.network 'private_network', ip: '192.168.33.300'   # 300 invalid octet

# after:
config.vm.network 'private_network', ip: '192.168.33.10', netmask: '255.255.255.0'
Defensive patterns

Strategy: validation

Validate before calling

require 'ipaddr'
def valid_vagrant_ip?(v, netmask = nil)
  IPAddr.new(v.to_s)                      # raises on malformed ip
  IPAddr.new("#{v}/#{netmask || 24}")      # raises on bad ip/mask combo
  true
rescue IPAddr::Error, ArgumentError
  false
end
abort 'bad ip' unless valid_vagrant_ip?('192.168.33.10')

Type guard

require 'ipaddr'
def vagrant_ip_string?(v)
  v.is_a?(String) && (IPAddr.new(v) rescue nil) ? true : false
end

Try / catch

begin
  env.cli('up')
rescue Vagrant::Errors::NetworkAddressInvalid => e
  d = e.extra_data
  warn "Fix network address #{d[:address]}/#{d[:mask]}: #{d[:error]}"
end

Prevention

When it happens

Trigger: A `config.vm.network 'private_network'/'public_network', ip: <bad>` value that Ruby's IPAddr rejects: typos ('192.168.1.256'), quotes around CIDR handled wrongly, IPv6 with zone or truncated address, e.g. during `vagrant up`/`reload`/`ssh-config` when networks are configured.

Common situations: Typos in static IPs; using a hostname instead of an IP; missing netmask combined with an odd prefix string; ERB templates injecting empty strings for the ip; copy-pasting 'ip: 192.168.33.10' without quotes after a YAML interpolation.

Related errors


AI-assisted analysis of hashicorp/vagrant@35f3160f4a (2026-08-21). Data as JSON: /api/errors/6a9b38f280bca4e1. Report an issue: GitHub.