Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 496
grepsedawk Avatar asked Apr 28 '15 14:04

grepsedawk


People also ask

Is vagrant compatible with VMware?

HashiCorp develops an official VMware Fusion and VMware Workstation provider for Vagrant. This provider allows Vagrant to power VMware based machines and take advantage of the improved stability and performance that VMware software offers.

What is the alternative for vagrant?

VirtualBox, Ansible, Packer, Terraform, and OpenStack are the most popular alternatives and competitors to Vagrant.

How do I connect my vagrant box to SSH?

Simply CMD-SHIFT-P then "Remote-SSH: Connect to Host..." and the ssh . config entry you just added is automatically listed - you simply select it and voila, vscode connects to your remote vagrant vm!

Which network should the network bridge to vagrant?

Default Network InterfaceIf 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.


2 Answers

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.

like image 170
grepsedawk Avatar answered Oct 21 '22 20:10

grepsedawk


According to this bug thread, people encountered the same issue when they were using vmware_fusion as provider; while is was working with a virtualbox provider.

It seems that a v3.2.0 of the VMware Fusion/Workstation plugin have been released with a bugfix for this. Try to update your VMWare Plugin to this version and test it again.

But if we take a look at the Vagrant VMWare Plugin for 3.2.0, it mentions:

core: static IPs work for public networks (private networks have always works)

And nothing in the newly released versions (> 3.2.0) seems to fix this.

like image 43
PierreF Avatar answered Oct 21 '22 18:10

PierreF