Search code examples
vagrantvagrantfile

Vagrant VMWare Public: Unable to set static automatically


I am using the VMWare Plugin. I am currently using the following :

config.vm.network "public_network", ip: "172.17.255.13", netmask: "255.255.255.0"

It does indeed make a BRIDGED connection, however it is a BRIDGED DHCP Connection.

Has anybody used static IP's successfully?

It is a CentOS-6.6 Box.

Update: It was the particular VM configuration, the creator didn't delete a file in /etc/ that needs to be cleared before VM packaging


Solution

  • I came up with a pretty elegant solution while waiting for this to get patched by the vagrant-vmware-workstation plugin team.

    I set up vagrant set up a public_network with auto_config set to false. (So vagrant doesn't overwrite the file I change)

    config.vm.network "public_network", auto_config: false
    

    After I set that up, I can run a shell provisioner to echo to the file that contains the settings for eth1 (eth0 is always vagrant's host only network)

    config.vm.provision "shell" do |s|
        s.path = "setIP.sh"
        s.args   = ["192.168.1.150", "255.255.255.0"] #ip/netmask
        privileged = "true"
    end
    

    It runs a shell script passing the IP and Netmask into the shell script as arguments.

    The shell script modifies /etc/sysconfig/network-scripts/ifcfg-eth1 (the config file for eth1 in CentOS-6.6) then proceeds to restart networking to make the settings take effect.

    setIP.sh:

    echo Setting IP to $1, Netmask to $2
    cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-eth1
    
    #PACHONK SET-IP CONFIG BEGIN
    IPADDR=$1
    NETMASK=$2
    ONBOOT=yes
    DEVICE=eth1
    #PACHONK SET-IP CONFIG BEGIN
    
    EOF
    
    #Restart networking to make IP active
    /etc/init.d/network restart
    

    Like I said, looks like it's been a bug for awhile. I created the most elegant fix I could for the time being.